## Efficient methods of searching vectors for specific int's that meet a condition?

I'm trying to write an efficient operation to search through a vector, specifically identify the existence of three int's (A1, A2, A3) where A1 > A2 && A2 < A3. So given A {5,3,1,2,3}, the operation with output: [3,1,2], [3,2,3],[5,1,3], ...
more »

## Prefix search against half a billion strings

I have a list of 500 mil strings. The strings are alphanumeric, ASCII characters, of varying size (usually from 2-30 characters). Also, they're single words (or a combination of words without spaces like 'helloiamastring'). What I need is a fast way...
more »

## How to efficiently find 10 greatest numbers from billions of numbers?

Problem Statement: Find 10 maximum numbers from a file which contains billions of numbers Input: 97911 98855 12345 78982 ..... ..... I actually came up with the below solution which has best case complexity O(n) - When file has numbers in desce...
more »

## Algorithm to merge multiple sorted sequences into one sorted sequence in javascript

I am looking for an algorithm to merge multiple sorted sequences, lets say X sorted sequences with n elements, into one sorted sequence in javascript , can you provide some examples? note: I do not want to use any library. Trying to solve https://ic...
more »

## Algorithm Complexity: Is it the same to iterate an array from the start than from the end?

In an interview I was asked for the following: public class Main { public static void main(String[] args) { // TODO Auto-generated method stub int [] array = new int [10000]; for (int i = 0; i < array.length; i++) { // do ca...
more »

## C Multiple arrays permutations algorithm

I'm trying to write a program that generates permutations upon a list of words stored into several arrays. For example, my program asks for 2 groups of words like this : words #1: abc def ghi words #2: 123 456 What i'm trying to have is this outp...
more »

## How to create an incidence array from random array objects?

Given the following: var dataSource = [ {X: 0, Y: 0, ApiKey: "Something"}, {X: 100, Y: 0, ApiKey: "Something"}, {X: 1500, Y: 200, ApiKey: "Something"}, {X: 1600, Y: 850, ApiKey: "Something"}, {X: 0, Y: 750, ApiKey: "Something"}, {X...
more »

## Time Complexity of permutation function

Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] My Iterative Solution is : public List<Li...
more »

## Check 4 consecutive identical diagonal elements in 2D Array (connect 4 Game)

I am working on implementing connect 4 Game on java. I have almost finished the program that simulates the Game. I use a 2D character array char [][] board = new char[6][7]; to represent the Grid of the game. I have implemented checkHorizantal me...
more »

## How to efficiently generate combination without repetition with certain distinctive number between them

How to efficiently generate sets of number combination without repetition where all sets has certain distinctive number between each other. *NOTE : Range number will always start from 0. Example : Range Number (numbers[ ]) = 0,1,2,3,4,5,6,7 ==> ...
more »

## How can the runtime of following approach be O(N) and space-complexity be O(1)?

Can anyone explain how does the approach to the given problem described below operate in O(N) time and O(1) space? Question: Given 2 sorted arrays, find the number of elements in common. The arrays are same length and each has all distinct elements....
more »

## XOR on contiguous subarrays of an array

From an array, I need to find the value obtained by XOR-ing the contiguous subarrays, following by XOR-ing the values thus obtained. INPUT One line containing integers that are elements of the array. e.g. [1,2,3] OUTPUT Print the answer correspo...
more »

## Memory leak after algorithm in Rails?

I wrote an algorithm inspired by the merge part of the merge sort. def self.merge(arr) if arr.length == 1 return arr end groups = [] (0...-(-arr.length/2)).each do |i| groups << [] if !arr[2*i+1].nil? ...
more »

## Duplo railroad - Formalize a "switchable direction node"

maybe a strange question here. My kids have Duplo railroad and I'd like to use some programming to create blueprints for them. The question I'm struggling with is how to define (describe, formalize etc) the part that has switchable direction. Here's ...
more »

more »

## Graph search algorithm with fewest accessed nodes

I need an algorithm to find ANY path from point A to point B in a graph. The problem is that finding out wich nodes can follow a specific one needs a quite lengthy matlab simulation, so i want to access as few nodes as possible. I know some heuristi...
more »

## Simple Search function with jQuery to search items doesn't work

I am trying to making a simple app that calls an api and get users data. When users data displayed on the page I want to search users with their usernames. tried many many times but its not working. Can anybody please help? var base = "https://a...
more »

## Sort an array of integers into odd, then even

I have a problem I found on an algorithm forum elsewhere. I have an array with random numbers (for example, [5, 2, 7, 9, 2, 3, 8, 4]) which should be returned to me sorted by odd then even. The order of the odds/evens is not important so in the exam...
more »

## Why Is This Factorial Algorithm Not Accurate

Sorry I feel stupid asking this and am prepared to lose half of my points asking this but why does this algorithm not work? It works up to a point. After the number 13 the factorials are a little off. For instance the numbers do not entirely match in...
more »

## How can I write a SQL Server stored procedure to get the following output?

I have a SourceTable like this with 2 column names: Col 1 | Col 2 ------------------ A | 2 B | 3 C | 4 D | 2 E | 1 F | 0 The first column has some letter, and the second column carries its f...
more »

## Performing a Binary Search

I am performing a binary search , let say i have to find the minimum value of x such that black_box(x) gives me true result. Property of black_box(x) If black_box(x) gives me true then x+1,x+2,x+3,x+4....upto infinty all gives me true For Intege...
more »

## Trying to find the number of x's that satisfies n + x = n ^ x fails with timeout

I'm trying to solve the following problem from the section Bit Manipulation at the Hacker Rank site using new features of Java 8 such as Streams. The problem description: Given an integer, n, find each x such that: 0 <= x <= n n ...
more »

## How to add two numbers in Javascript "without using `+` or `-` operators"?

Update: This is NOT a basic "how to add numbers in JavaScript" question Please read the question carefully before downvoting I know an alternative to using the + sign for addition is to do something like this: int add(int a, int b) { ...
more »

## Average face - algorithm

Quesion and code is at the end I hope this question belongs here and not to the TCS's stack. I am trying to go through algorithms in Turk and Pentland's "Eigenfaces for Recognition". On page 74 one can read (last paragraph of left column): Let t...
more »

## How do I find the percentage of similarity between two multiline Strings?

I have got two multi-line strings. I'm using the following code to determine the similarity between two of them. This makes use of Levenshtein distance algorithm. public static double similarity(String s1, String s2) { String longer = s1, sho...
more »

## Efficient Algorithm to Replace All SubArrays with Other SubArrays

I have a byte array(can get very large, past 32 million bytes), and I need to replace some subarrays that with other subarrays of the same length. My current approach is search the byte array for all the subarrays I need to replace, every time I fin...
more »

## Wagner Fischer algorithm + display steps

I made an implementation of Wagner Fischer algorithm in java with input cost, but I want to display all steps. I search but can't find any idea.After a long time I tried to keep each transformation in matrix alongside cost and to go through back to f...
more »

## Adding and subtracting a set of numbers to reach a value

From a vector of float numbers std::vector<float> v { 0.32, 0.0004, 12.78, -9.2, 1.1 }; I am trying to find out what series of "+" and "-" one can place in front of each float number to get a result that is as close as possible as the value ...
more »

## non-binary tree search and insertion

I searched a bit but haven't found the answer to this question.. I built a non-binary tree, so each node can have any number of children (called n-ary tree i think) To help with searching, I gave every node a number when i built the tree, so that e...
more »

## hide show custom filter in ng-repeat that uses table

How can I use custom filter to hide inventory column of color pencil special on date 2-10-2017 in the view? color pencil special's inventory is depends on color pencil's inventory which in this case it's located somewhere. \$scope.stationary = [{ ...
more »

## What is the space complexity of this code?

int f(int n) { if (n <= 1) { return 1; } return f(n - 1) + f(n - 1); } I know that the time complexity is O(2^n) and I understand why. But I don't understand why the space complexity is O(n). I was told that it's be...
more »

## How to apply test functions to genetic algorithm

I have written following code for population evolution (Genetic Algorithm Implementation): Individual.java import java.util.Random; public class Individual { public static int SIZE = 500; private int[] genes = new int[SIZE]; private d...
more »

## How to generalize my algorithm to detect if one string is a rotation of another

So I've been going through various problems to review for upcoming interviews and one I encountered is determining whether two strings are rotations of each other. Obviously, I'm hardly the first person to solve this problem. In fact, I did discover ...
more »

## Divide and conquer trominos algorithm in C

This is the classic divide and conquer problem. We have a 2^n * 2^n board and we want to fill it with L shaped cubes. We know there is one block on the board that we can't assign a cube. This problem is also known as tromino problem (somewhat). Prob...
more »