Category "algorithm"

Minimum number of swaps required to make a binary string palindrome

Give a binary string consisting of 0's and 1's only. E.g., 0100101. We are allowed to pick any two indexes and swap them. We have to return the minimum number o

Get PDF images in an array using PDFIUM to edit them

I am trying to write down a method to get all PDF images from a FPDF_DOCUMENT object to perform actions on them and return back theFPDF_DOCUMENT with the images

Solving a Chain Link Python Puzzle:

I am not sure where to start with the following python puzzle. "You are holding a link of a chain. Implement a method longerSide to find which side of the chain

heapify VS build heap

Can you please confirm the meaning of the concept 'heapify', the source I am learning from says that heapify is building a heap from an array (from scratch) Thi

Find the max value of the same length nails after hammered

I'm trying to solve this problem: Given an array of positive integers, and an integer Y, you are allowed to replace at most Y array-elements with lesser val

Problems with using a rough greyscale algorithm?

So I'm designing a few programs for editing photos in python using PIL and one of them was converting an image to greyscale (I'm avoiding the use of any functio

Swapping elements between A and B to get sums equality

We have two arrays of equal length, A and B. also, for every i: 0 <= a_i, b_i <= m for some 1<=m<= 1000000. We want to check if a single swap bet

Grouping/Clustering Rectangles

I have a list of shapes (list of points) e.g. rectangles which I want to group/cluster together. This is what I have: And this is what I want to achieve. How

Algorithm to find the most frequent words [closed]

I can't think of an algorithm for my code. Please help me out. We have two files. The first one has text (Text length is n-words). The second

how to convert binary heap sort to d_ary heap sort?

Hi I have an algorithm that uses binary tree to heapify and then sort the list i need to convert this sort algorithm to change into d-heap or d-ary heap or k-ar

Remove Duplicates from sorted list not passing all testcases

This is a question on leetcode. For some reason my code only works for 7/164 test cases. i would like to know why my algorithm is not efficient. what is a solut

Diagonal difference of a nested List C#

I'm trying to get from a function the absolute difference of a nested list. I have a fixed matrix, and I would like to get the result when is not fixed. At the

Find optimum in combination of groups out of individuals due to certain criteria

I would like to form random groups out of a number of individuals. For the individuals I have information about their location (two possibilities) and the team

Integer Programming for NNC

I'm trying to implement Integer Programming for Nearest Neighbor Classifier in python using cvxpy. Short intro Given a dataset of n points with a color (red or

Integer Programming for NNC

I'm trying to implement Integer Programming for Nearest Neighbor Classifier in python using cvxpy. Short intro Given a dataset of n points with a color (red or

How solve Codility equiLeader challenge

After finding the "leader" I tried finding the possible equiLeaders in the given array but couldn't. Tried to find a solution of someone else but can't wrap my

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product. and here is my code function adjacentEle

Sort a List in Dart based on how another List was sorted

I am trying to sort a list with reference to another list. Consider this example, List<String> a = ["a", "b", "c"]; List<int> b = [2, 3, 1]; Now,

Custom Hashing Algorithm

Out of sheer boredom, I decided to write a hashing algorithm in python. It all works, however I've got a couple problems: Results are similar (e.g. hash(1234)

Does the .includes method in JavaScript loop through the array and case O(n)?

Does the .includes method cause O(n^2) when run with another loop such as in this simple example? function myFn(){ let age = people.map(person => {