An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

learn more… | top users | synonyms

0
votes
0answers
12 views

Puzzle 8 Resolver in Python - I can't find frontier neighbors correctly and quickly

I have to do a 8 puzzle resolver with bfs, dfs and A* algorithms in python, but I have some issue(s). This is my output for python driver_3.py bfs 1,2,5,3,4,0,6,7,8:...
3
votes
2answers
65 views

Foobar Fuel Injection Perfection efficiency

I was writing this code and was using the BigInteger class because it needs to work with numbers up to 309 digits long, however it takes too long to run with numbers that are too big. I was hoping to ...
0
votes
0answers
27 views

My binary search algorithm implementation in JavaScript

I have implemented binary search algorithm in JavaScript, Its as follows, ...
1
vote
0answers
43 views

Generating all permutations of a given array

I have written this Java snippet to generate all permutations of a given Array of a HashMap. Can this be done in a better way? ...
4
votes
2answers
57 views

MySQL parser written in Python3

As the title suggests, I'm building a MySQL parser in python. The intention of this is to better support application development by managing migrations in a more declarative way. You can read about ...
6
votes
1answer
40 views

LLVM Pass that renames all functions

Below is an LLVM pass that I've written to rename all functions in an LLVM bitcode file. I would appreciate tips on what is well done and what is poorly done in the code below. In particular, is there ...
2
votes
1answer
44 views

JavaScript Website-Content Grabber

I my firm a few people have following problem: A Content Management System is hosted externally. The treaty doesn't include database-access. In September the treaty will expire. So they have to get ...
-2
votes
0answers
23 views

chess problem (check the check) [on hold]

I am trying to solve the problem from http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=110107&format=html But system shows me - wrong answer. I have checked a lot of ...
2
votes
1answer
59 views

“The Story of a Tree” solved using depth-first search

Found this problem in hackerrank. One day Bob drew a tree, with \$n\$ nodes and \$n-1\$ edges on a piece of paper. He soon discovered that parent of a node depends on the root of the tree. The ...
1
vote
2answers
35 views

From an given array of numbers remove duplicate values

I was asked an question for writing a program where the input will be array of numbers; the output of the program will be array of numbers without duplicates. I coded in javaScript which runs on ...
2
votes
1answer
33 views

Convert decimal to binary and find the maximum number of consecutive 1's in the binary

Task: given a base- 10 integer, n, convert it to binary (base-2). Then find and print the base- 10 integer denoting the maximum number of consecutive 1's in n's binary representation. What can you ...
3
votes
1answer
41 views

Retrieve a number in a webpage and store in a SQLite3 db

I'm beggining Python. So I wrote a program which is supposed to get a number of connected people on a forum (like this one : http://www.jeuxvideo.com/forums/0-51-0-1-0-1-0-blabla-18-25-ans.htm) and ...
4
votes
3answers
121 views

My Binary Search Implementation

I have implemented binary search in JavaScript. I run it on node. I pass an comma separated string of numbers in ascending order as first argument and the number to be searched in the second ...
2
votes
1answer
36 views

Union and intersection of two arrays

Problem: Write an algorithm, to find the union and intersection sorted in ascending order, between the elements of two arrays Input Format The first line contains an integer, n1 , ...
-2
votes
0answers
46 views

Google Foobar Level 4 Running With Bunnies [closed]

This is the Problem i am having problem with. I have written the code for it. but it is arrayoutofbound exeception for some unknown input. You and your rescued ...
1
vote
1answer
23 views

Comparing and counting thousands of dates converted using moment.js

I have a very large list of users (a Mongo Collection with roughly +4000 users). Each user belongs to a site. On the client-...
3
votes
2answers
101 views

Find the Thief - Coding Challenge - JavaScript Implementation

About a week ago (maybe less), I posted this and I didn't really have a 100% full-proof working implementation, but I think I have got it now. First of all, here is the coding / algorithm challenge ...
2
votes
2answers
60 views

Find all occurrences of all permutations of a shorter string within a longer string

Input is two strings, the first string being the long string and the second smaller string being the permuted string. The output should return the starting indices of all occurrences as well as the ...
2
votes
1answer
19 views

mo algorithm for summing the subarray

Below is the implementation of MO algorithm for summing the sub array given the range as input. As MO algorithm is a offline query it is given a list of ranges as input. Below code calculates the ...
3
votes
1answer
142 views

Parsing a Conditional statement with Python

Recently I built a Usenet newsreader in Python and for that I built a keyword search which supports AND and OR functionalities (e.g., python AND django should bring up articles containing both. I ...
2
votes
4answers
50 views

Assembler-program which reverses the content of EAX

Following exercise: "Write a program that takes a number (of size 4 bytes) x as input, and then reverses all the bits of x, and outputs the result. By reversing all bits we mean that the bit ...
3
votes
1answer
41 views

Terminated due to timeout Mapping phone numbers

I have a code based on the following problem "Mapping phone numbers to names", the problem is that when they are going to process large data(+100.000) the program ends by timeout. my code and problem ...
1
vote
0answers
42 views

Using BFS to solve 8-puzzle game using Python 2

I'm trying to solve the 8-puzzle game using BFS, DFS and A* algorithms implemented using Python 2.7. For now, I have managed to solve a couple of test cases using BFS and I want to know how I can ...
2
votes
1answer
270 views

Google Foobar bomb_baby

This is the question I am facing at level 3 of Google Foobar: There are two types: Mach bombs (M) and Facula bombs (F). The bombs, once released into the LAMBCHOP's inner workings, will ...
-1
votes
0answers
81 views

Find largest item association group

I have a solution for association relationships to find largest item association group. If any item matches the item with another group then combine those groups to form a new group with related items....
3
votes
1answer
38 views

KQuery SPOJ problem, using merge sort segment tree

Problem : KQUERY Summary: For each query consisting of \$(i, j, k)\$, return the number of elements greater than \$k\$ in the subsequence \$a_i, a_{i+1}, …, a_j\$. My code has complexity of \$O(n\...
0
votes
1answer
47 views

Queue/stack/node class Implementation

Below there are 3 short header files for queue, stack, and node implementation. I do ...
7
votes
1answer
72 views

Counting nodes in a binary tree with odd values, using an iterative algorithm

I've to simulate exactly a recursive algorithm with an iterative one. Assuming that I have a binary search tree that contains only a key and two references at his right and left child I want to do ...
1
vote
1answer
42 views

Hackerrank “Queues: A Tale of Two Stacks” Javascript Solution

Here is the original problem, and below is my solution (passing). It's asking to implement a queue with 2 stacks, which means I cannot simply use Array.shift. I wonder if the solution can be improved. ...
0
votes
1answer
45 views

An algorithm that finds a sequence of numbers to fill a square grid

Given numbers 1,2,3,4,5,6,7,8 I need them to replace the x's so that each side adds up to the number in the centre. ...
0
votes
1answer
38 views

Compute all possible attendance records with length n, which will be regarded as rewardable

Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after \$\mod 10^9 + 7\$. ...
4
votes
0answers
62 views

Minimum number of moves to solve “game of fifteen”

I read about this game and tried to make my own algorithm to solve this. I asked it on StackOverflow for the appropriate algorithm and logic to solve this problem. With the help of answers over ...
5
votes
2answers
81 views

Non-recursive implementation of MergeSort

I've been trying to internalize some of the basic sorting algorithms recently, and to do so I've been looking at their wikipedia pages to refresh myself with how they work, and then coding my own "...
3
votes
1answer
65 views

Find next bigger number with same combination of digits

Please review my code for a puzzle to find next bigger number with same combination of digits. so if the number is 156432 the next bigger number is 162345 I wrote a program which is as follows, <...
2
votes
0answers
29 views

Algorithm for point distribution of traversal between 2 points on a line in time

Not sure if this is best SO forum to post at, please suggest/move to more appropriate place otherwise. A synopsis of the problem 1st: Given a scenario where we have messages with data that define a ...
1
vote
1answer
38 views

Hackerrank CTCI “Stacks: Balanced Brackets” Javascript Solution

Here is the original problem, and below is my solution. I wonder what can be improved? Or is there a fundamentally better algorithm out there? Thank you! My intuition is telling me that it can be more ...
-1
votes
1answer
36 views

Efficient Hangman algorithm [closed]

I'm trying to find the most efficient algorithm for solving Hangman. For those who are not familiar, it's a game where people need to guess the correct letters in a word. I've written the following ...
4
votes
1answer
39 views

Prim's Lazy Minimum Spanning Tree Algorithm in Haskell (Project Euler# 107)

I have implemented Lazy version of Prim's Minimum Spanning Tree Algorithm. I want to improve the code structure, follow prevalent conventions and reduce code size. I am solving Project Euler #107. ...
3
votes
2answers
79 views

Check if a string is palindrome or two strings are the opposite of each other

I made a function which checks if a word is the opposite of each other (ex: word and drow) and then realized that with minor changes it could also be used to detect if a word is palindrome. They both ...
4
votes
1answer
67 views

Find Eulerian Tour Algorithm - with multithreading and random permutations

After struggling for a long while on this through the algorithms course on Udacity, I finally understood enough of the concept to develop this implementation. However, it lacks efficiency and finesse. ...
4
votes
1answer
53 views

Repeated comparison of sorted subarrays

This question is from a recently concluded competition on Codechef. You are given an array A of size n, and there are ...
8
votes
2answers
353 views

method to decide if two strings are anagrams

I'm studying with the Cracking the Code Interview book. I'm just looking for some feedback on this method: C++ ...
3
votes
1answer
79 views

Hackerrank “Hash Tables: Ransom Note” Javascript Solution

Here is the original problem, and here's my solution: ...
12
votes
4answers
1k views

Codechef: Prime Number Generator

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers! Input The input begins with the number t ...
7
votes
2answers
347 views

Computing sum on column + sum on row + sum on each diagonal

I have the following problem: I read from a file the dimension(n) of the matrix(which is n * n) and the matrix. For each element ...
5
votes
3answers
288 views

finding the conflicts in meetings given startTimes and end Times

Code to find conflicts in a list of meetings given as input. Meetings are defined as {startTime, endTime}. I am using a Greedy Algorithm to find the conflicts. Wanted to know if there is a more ...
4
votes
1answer
118 views

Floor the larger number

floor[1*e] + floor[2*e] + floor[3*e] + ... + floor[n*e], where floor[x] is the largest integer that is not greater than x, and e is Euler's number: 2....
3
votes
1answer
31 views

Sorting a singly linked list with natural merge sort in C

This C program implements a so-called natural merge sort that identifies existing runs in the list and exploits them in order to sort in sub-linearithmic time whenever possible. The running time of ...
12
votes
6answers
1k views

Check string has unique chars only

Following is my code to check if string has unique chars. I am assuming string would have only ascii chars. ...