Convert Sorted Array to Binary Search Tree

I am working on "Convert Sorted Array to Binary Search Tree With Minimal Height", which asked: Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. I am not able to find why my recursive does not stop...
more »

2017-07-12 15:07 (2) Answers

Best algorithm to generate even strong teams

I got a list of players with a skill from 0-100 and a list of teams which have all their own members list. Now I want to put the players to the teams so that teams mostly got the same size (+-1 difference is ok) and the sums of the skills should be...
more »

2017-07-06 05:07 (1) Answers

Filling a plane with triangles (Triangulation)

I tried to create an image like the one below as a random background for a website, but after multiple attempts I couldn't find an algorithm that gets the job done. What should the program do? It should be able to fill a plane randomly with trian...
more »

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

Python Negamax Algorithm

I have about as simple of a negamax algorithm as possible, for evaluating positions in Tic Tac Toe. The state of the game is stored as an array in numpy, with X's pieces represented by 1, and O's pieces represented by four. I was testing this just ...
more »

2017-07-02 19:07 (1) Answers

Is my Simpson's rule calculator correct (java)?

I'm supposed to calculate using Simpson's rule, with 4 sub intervals. I surely do not want do it by hand so I have tried to write that algorithm in Java. The formula for Simpson's rule is And here is my code: import java.util.Scanner; imp...
more »

2017-07-01 00:07 (2) Answers

Merge Sort tracing clarification

I'm having a little difficulty of tracing the process of merge sort... Conceptually, I understand that an unsorted array will be divided until its sub-arrays of sub-arrays become the length of 1, in which it becomes an array that contains 1 elements ...
more »

2017-06-30 08:06 (1) Answers

Find a matrix which satisfies certain constraints

Another description of the problem: Compute a matrix which satisfies certain constraints Given a function whose only argument is a 4x4 matrix (int[4][4] matrix), determine the maximal possible output (return value) of that function. The 4x4 matrix ...
more »

2017-06-27 15:06 (3) Answers

Best time to Buy and Sell stock modified version

Say you have an array for which the ith element is the price of a given stock on day i. If you can do unlimited times of buy and sell (can only hold one stock at a time), but each time you sell you need to pay transaction fee, please calculate the m...
more »

2017-06-27 01:06 (3) Answers

Working with variable sized lists with Cython

I want to cythonise the python implementation of the Sutherland-Hogman algorithm. This algorithm updates a list of vertices according to pretty simple rules (being inside or outside an edge, etc.) but the details are not important. Here is the python...
more »

2017-06-26 19:06 (0) Answers

List the elements that appeared in both list?

Given two sorted arrays(without duplicates of course), is there a way to find out and print all the elements that appeared in both arrays? I know if could get by iterating through one array and build a hashtable, and then iterate the other array and...
more »

2017-06-23 02:06 (4) Answers

Filtering logs with regex in java

The description is quite long, so please bear with me: I have log files ranging from 300 mb to 1.5 Gb in size, which need to be filtered given a search key. The format of the logs is something like this: 24 May 2017 17:00:06,827 [INFO] 123456 (B...
more »

2017-06-21 10:06 (2) Answers

Why does this loop terminate partway through?

I'm trying to write a program to find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters. The range will be an array of two numbers t...
more »

2017-06-20 23:06 (1) Answers

Finish n jobs in d steps by backtracking

I have several groups of tasks, each group is a chain of tasks, groups are independent of each other. Tasks within a group can only be processed in the order which is determined by the chain of that group. Each task has an ID and a cost. Tasks are ...
more »

2017-06-20 14:06 (1) Answers

Exchange sort algorithm in c using pointers

I am trying to write an exchange sort in c using pointers, NOT indices; I do not understand why this code does not work: void sort(int a[], int n) { int *i, *j, *temp; int * const end = a + n; for(i = a; i < end - 1; i++) for(j = i + ...
more »

2017-06-19 19:06 (1) Answers

digital root sort algorithm

I'm running through challenges on codefight and all tests pass except 1 "hidden test" where I'm unable to see the test data inserted... I'm looking for help pointing out what I'm missing or a failing test case with my solution. Problem: Digit ro...
more »

2017-06-18 23:06 (1) Answers

Rotate the indices on a hexagon

I have hexagons made of little unit hexagons. Each hexagon has a hex number of unit hexagons. The first few are numbered like: Size 1: 0 Size 2: 0 1 2 3 4 5 6 Size 3: 0 1 2 3 4 5 6 7 8 9 A B C D E F 101112 (Last one is in hexad...
more »

2017-06-17 19:06 (4) Answers

Solving crosswords

I have a crossword puzzle and a list of words which can be used to solve it (words can be placed multiple times or not even once). There is always a solution for the given crossword and word list. I searched for clues on how to solve this problem an...
more »

2017-06-17 18:06 (1) Answers

How to abbreviate a full name in C?

I am trying to get a full name from the user and display his name abbreviated, something like that : “Edward Cantrell Cavender Davis” --> Name the user entered "DAVIS, E. C. C.” -- Name abbreaviated The problem is that I don't know how ...
more »

2017-06-15 16:06 (3) Answers