An algorithm is a precise plan (in the format of a sequence of steps) on how to solve a particular problem.

learn more… | top users | synonyms

1
vote
1answer
36 views

Quick sort implementation in JavaScript in prototype style

I have implemented quickly the quick sort algorithm in JavaScript using prototype based style. The code is rather short (http://jsfiddle.net/b8mfY/): ...
2
votes
1answer
29 views

select_best: yet another partitioning algorithm

The title is somewhat a misnomer; my apologies. The goal of the procedure is to partition a range of first, last by mid for the ...
2
votes
0answers
40 views

Best way to traverse an almost complete undirected weighted graph

I need help with an optimized solution for the following problem http://acm.ro/prob/probleme/B.pdf. Depending on the cost i either traverse the graph using only new edges, or using only old edges, ...
6
votes
3answers
268 views

Simplifying a path

Please be super brutal, and treat this as a top technical interview. Worst case analysis: \$O(n)\$ (please confirm) Space complexity: \$O(n)\$ Problem: Given an absolute path for a file ...
5
votes
1answer
73 views
0
votes
0answers
14 views

Image coordinates calculation algorithm [on hold]

I was looking at Jcrop library code for scaled image size calculation, but I couldn't clearly understand algorithm used in following function: ...
3
votes
1answer
30 views

Tarjan's algorithm for Strongly Connected Components without keeping SCC in stack

I've been looking for an implementation of Tarjan's algorithm in C#/C++ for a strongly-connected components in graphs, and couldn't find any implementation without use of additional Stack - most of ...
-1
votes
0answers
14 views

Using linked list to make a simple version of word/sentence predicting software (e.g T-9) [on hold]

Hey Guy/Gals, I want to develop a simple program using linked list/trees for predicting words or sentences WITHOUT using file handling because i haven't been taught file handling yet ...
2
votes
0answers
33 views

Lift ball which leads to shortest height

There are n balls kept on a table and connected by same singe connected string (which can be cyclic or maynot). Write the code to select a ball such that after lifting the whole structure from that ...
4
votes
2answers
76 views

Finding alternating sequence in a list of numbers

Please be brutal and treat this as me coding this up for an interview. A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between ...
0
votes
0answers
15 views

What formula is this? [on hold]

So I came across a very neat solution to this problem. ...
3
votes
1answer
46 views

Grouping Anagrams

Please be über brutal, and treat this as a technical interview question. I was wondering how this function that I wrote looks like. It groups together words that have the same alphabets (i.e ...
4
votes
2answers
77 views

Method to separate a list of ports to scan

I'm building a port scanner as an exercise. It contains a method to separate the ports that the user wants to have checked, which can include single ports and port ranges, ex: 22, 23, 80-120, 443-500, ...
3
votes
0answers
56 views

Aho-Corasick string matching in Haskell

I implemented Aho-Corasick string matching in Haskell. It is a purely functional implementation compared to many other implementations. The input to build an automata is ...
2
votes
0answers
36 views

Segment tree in Python3

I've implemented a Segment Tree in Python3: ...
7
votes
2answers
39 views

In place quicksort

I implemented my own sorting in VBA because it doesn't provide its own, and it's healthy to test yourself. It was surprisingly difficult and I ended up make a few tweaks that I didn't expect to make ...
2
votes
0answers
44 views

Get all combinations of a list of numbers [closed]

This is code I found online HERE, to use in a review HERE. However I noticed the code was very bulky and doesn't take advantage of IList, ICollection or IEnumeral, so I know it can certainly be ...
1
vote
1answer
37 views

Print left view of the tree

Left view of a Binary Tree is set of nodes visible when tree is visited from left side. Left view of following tree is 12, 10, 25. ...
9
votes
2answers
326 views

Codility - Perm-Missing-Elem: 100% functional score, but only 60% performance

I can not figure out why I didn't get 100% success from the Codility's Perm-Missing-Element test even I solve with \$O(n)\$. I will appreciate any advice/answers. You can see the problem, my code, ...
0
votes
0answers
23 views

Solving sudoku in C [closed]

After hearing about backtracking , i wrote this piece of code to solve sudoku , but it seems to give wrong solutions , what exactly i am doing wrong here ? ...
7
votes
3answers
421 views

Find Minimum Number of coins

Please be brutal, and treat this as a top 5 technical interview. I am trying to follow Google's way of writing Java code, as per their .pdf file online of code review. (Side note: do any of you see ...
3
votes
1answer
79 views

Hackerrank - Sherlock and the Beast

I am trying to solve the Sherlock and The Beast HackerRank challenge. Most tests timeout, however when I try a custom stretch test case (T = 20 and all N = 100000), it returns successfully, so I'm not ...
4
votes
4answers
157 views

Find the value nearest to k in the sorted array

Given a sorted array returns the 'closest' element to the input 'x'. Note, I do understand merits of unit testing in separate files. But deliberately added it to main method for personal convenience, ...
12
votes
5answers
944 views

Longest palindrome in a string

Please be brutal, and judge my code as if it was written at a top 3 tech company, straight out of college. (The method signature, and input parameter is given by the problem, so don't worry about ...
0
votes
2answers
107 views

Tic-Tac-Toe implementation where computer should not lose

I have implemented Tic-Tac-Toe so that human can play with the computer, where the computer should never lose. I did a simple analysis before implementing, and I found out that there are certain ...
9
votes
1answer
142 views

QuickSort C# Implementation

It has been a while I haven't implemented a QuickSort and I wanted to write it down like I remembered. Here it is: ...
3
votes
2answers
66 views

Given an integer array of size n, find any three numbers

Return any three descending numbers that appear sequentially in the input such that A[i] > A[j] > A[k] and i < j < k. Since problem description contains 'any', I could not unit test using JUnit. ...
4
votes
3answers
57 views

Find the sum and multiply equilibrium

Finds the equilibrium. For sum/mult an equilibrium is defined as the index i at which sum/mult of all elements at ...
7
votes
1answer
47 views

Assembly line scheduling

This is solution to the assembly line problem. Here is complete description, which is too big and verbose to re-describe. I apologize for the inconvenience of the hyperlink. Note: I do understand ...
6
votes
1answer
53 views

Generic radix sort

This started out with my answer to Radix Sort on an Array of Strings?. Since I intend to write a generic radix sort for my own purposes anyway, I continued a little bit, and here is a version tested ...
3
votes
2answers
66 views

Find intersecting rectangle

Given two rectangles, return the intersecting rectangles. This class is thread-safe. It takes rectangles in two different representations, and returns the intersecting rectangle in the respective ...
11
votes
4answers
247 views

Least significant digit (LSD) radix sort of strings

I am learning string algorithms and wrote this C example based on a Java example I found online. Any feedback relating to style, code clarity, whether it is generic enough to be re-used, interface, ...
2
votes
1answer
96 views

Why does this Python maze-solver NOT get stuck? [on hold]

I wrote the following Python program, which reads text files as mazes and displays the solution with a trail of Xs. The files must have an S for the start and an E for the end, and the walls must be ...
4
votes
2answers
97 views

Counting matrices

I need help optimizing my code to run faster (it works but I get Time Limit Exceeded) for this problem. (Don't pay attention to readInt() function, its only used ...
8
votes
3answers
164 views

Longest Common Prefix in an array of Strings

Please be brutal, and treat this as if I was at an interview at a top 5 tech firm. Question: Write a function to find the longest common prefix string amongst an array of strings. Time it ...
3
votes
1answer
87 views

Expression tree creation from postfix expression

Given a postfix expression, construct an expression tree. Looking code code review, optimizations and best practices. ...
3
votes
2answers
33 views

Search/Match algorithm between 2 vectors

I have 2 vectors of Facebook like pages which are represented by an ID from 2 different users. I want to verify how many liked pages are the same between these 2 users. This is my algorithm that I am ...
5
votes
4answers
122 views

Find the sum along root-to-leaf paths of a tree

Most of you already know me, please be brutal, and treat this code as if it was written at a top tech interview company. Question: Given a binary tree and a sum, find all root-to-leaf paths where ...
4
votes
1answer
59 views

Reducing code duplication in a geometric function

Given a large bounding rectangle ("envelope"), a list of points, and a maximal aspect ratio, the goal is to find a rectangle within the envelope, whose aspect ratio is bounded within the given aspect ...
6
votes
2answers
71 views

Clone of an undirected graph

Perform a graph clone. Verifying complexity to be O(E). Looking for code review, optimizations and best practices. ...
3
votes
1answer
29 views

Infix to postix conversion

I'm looking for code review, optimizations and best practices. Also verifying complexity to be O(n), where n is the string length. ...
7
votes
4answers
183 views

Adding intervals to an interval store

Write a program to do addition of intervals to an interval store. An interval is represented by an array of two elements - the lower and the upper bound (you can assume integers). Assume ...
8
votes
3answers
95 views

Longest 'balanced' substring

I was given a task where given a string of '0's and '1's, return the longest substring where the count of '0's and '1's are equal. I was told also that the code should be O(n) and space O(1). Below ...
4
votes
2answers
79 views

Different factorial algorithm implementations and measuring their execution time

I'm new to C, and as an exercise I'm building 4 different factorial algorithm implementations and measuring their running time. I'm looking for this feedback, especially: The implementation of the ...
8
votes
2answers
76 views

Sorting and searching problem related to a group of people standing in a rectangle

Please be brutal, and let me know how I've done on this problem, provided I coded it at an interview for a top tech firm. Time it took me: 44 minutes Worst case time complexity: O(n2)? Am I right? ...
3
votes
1answer
51 views

Clone an undirected graph

I'm looking for code-review, optimization and best practices. Also verifying complexity to be O(E) time and O(V+E) space complexity. ...
1
vote
3answers
65 views

Preorder traversal of binary tree to produce formatted string

Given a complete binary tree returns the following format (Parent ( leftchild (leftchild, rightchild), rightchild(leftchild,rightchild) ). Looking for code review, optimizations and best practices. ...
5
votes
2answers
46 views

Pascal triangle produced for a particular integer K

Please be brutal and let me know what you think of the code below, if written at an interview. Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = ...
2
votes
1answer
31 views

Isomorphic trees verification

Two trees are called isomorphic if one of them can be obtained from other by a series of flips, i.e. by swapping left and right children of a number of nodes. Any number of nodes at any level can have ...