Mutating an array without extra space

I was given the following question in an interview, and couldn't find the solution. Given is an array of chars length n, and "important section" (all chars in this section must be saved) length m where n >= m >= 0 as follows: Without extra space...
more »

2017-04-18 15:04 (3) Answers

Cannon's algorithm of matrix multiplication

I try to implement the Cannon's algorithm of matrix multiplication. I read description on the wikipedia that provides next pseudocode: row i of matrix a is circularly shifted by i elements to the left. col j of matrix b is circularly shifted b...
more »

2017-04-16 19:04 (1) Answers

Reasons for using a Bag in Java

I am currently studying about Algorithms & Data Structures and while I was reading over the Book of Algorithms 4th edition, I discovered the Bag data-structure together with the Stack and Queue. After reading the the explanation of it, it is stil...
more »

2017-04-15 17:04 (1) Answers

maximum i-j , so that A[i]>=A[j]

Let us assume that we have an array A of positive integers. Our task is to find the maximum posible i-j , i>j that holds the following property : A[i]>=A[j]. To give an example , if A[0]=78 A[1]=88 A[2]=64 A[3]=94 A[4]=17 A[5]=91 A[6]=57 A[7]=69 ...
more »

2017-04-13 22:04 (1) Answers

JS - Create smart auto complete

Given a sorted Array of Strings, and user input I need to return the most relevant result. Example: Array =['Apple','Banana and Melon','Orange'] and user input = 'Mellllon' the returned value should be 'Banana and Melon' I'm looking for the right a...
more »

2017-04-13 15:04 (3) Answers

How SVN file merge works internally?

usecase 1:- Say two files File_v1 and File_v2 are merged through svn or any other tool. Once i take update thru svn on File_v2, how does it find it can merge it successfully or there is some conflict ? File_v1 File_v2 line1 line...
more »

2017-04-13 13:04 (0) Answers

Uniform Cost Search in Python

I have implemented a simple graph data structure in Python with the following structure below. The code is here just to clarify what the functions/variables mean, but they are pretty self-explanatory so you can skip reading it. # Node data structure...
more »

2017-04-11 21:04 (1) Answers

A* to recognize it's impossible to get to the goal

I implemented A* for the 8 puzzle problem pretty much word for word to the pseudo code in the wiki article but even though I have closed I still get infinite runtime on boards that should fail. It seems that the rate of opening new nodes is larger ...
more »

2017-04-11 17:04 (1) Answers

Update sorted list

I think there is common name for algorithm I am searching. I have a big list of players sorted by their score. e.g 1 million or billion players. Every second one player is changing its score and I wish to updated sorted list to keep it sorted and I ...
more »

2017-04-02 13:04 (1) Answers

How do I switch rows and columns in a 2D array?

I am working on a code that will create a visual Sierpinski triangle to 3D print, and in order for it to work I have to use a Pascal triangle algorithm that will create an array so I can use to tell my algorithm that will create my triangles where no...
more »

2017-04-02 04:04 (4) Answers

Optimizing 2D grid connectivity algorithm

Summary: I'm looking for an optimal algorithm to ensure connectivity over a 2D grid of binary values. I have a fairly involved algorithm that does it in effectively linear time, but only if certain pre-processing steps are performed. The following go...
more »

2017-04-01 22:04 (0) Answers

Multidimentional Knapsack with minimum and maximum

I have a problem which is similar to the Knapsack problem, more specifically the multidimentional variation. I have a bunch of objects which all have a cost, a value, and a category. I need to the Knapsack optimisation for value under a maximum cost...
more »

2017-03-31 19:03 (2) Answers

assign value as per ratio defined

I have one scenario here. Let me explain by small example. I have 10 pens, I have to give it to 3 people. Those person's ratio are like 6:6:1 means if I am giving 1 pen to Person C I have to give 6-6 pens to Person A and Person B. I have tried to s...
more »

2017-03-31 09:03 (4) Answers

Recognize if not enough resources during timeframe

i need an idea how to solve the following problem. Lets say i have one group with given timeframe (8:00-12:00) and i can assign resources (people) to it. Each resource can have a custom timeframe (like 9-10, 9-12,8-12 etc.) and could be assigned mul...
more »

2017-03-30 09:03 (2) Answers