# algorithm

• ## Complexity when generating all combinations2019-03-17

Interview questions where I start with "this might be solved by generating all possible combinations for the array elements" are usually meant to let me find something better. Anyway I would like to add "I would definitely prefer another so

• ## (LeetCode) Contains Duplicate III2019-02-26

Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j is at most k. Hello! I am kinda stumped by this ques

Tags: algorithm, java, tree
• ## Count occurences of digit 'x' in range (0,n]2019-02-24

So I'm trying to write a python function that takes in two arguments, n and num, and counts the occurrences of 'n' between 0 and num. For example, countOccurrences(15,5) should be 2. countOccurrences(100,5) should be 20. I made a simple iterative sol

• ## Getting Wrong Answer in "Longest non regular parentheses sub-sequence "codechef june cook off2019-02-19

I attended a programming competition(it has ended now). I don't know why my solution is giving WA, I read the editorial, saw other people solution but unable to find a flaw in my solution. Obviously I am missing somewhere. Please help! Question Link

Tags: algorithm
• ## How to check whether the letters of a string exist in the given order within another string?2018-12-09

I'm trying to make a program to check whether the word "nadia" is present with this sequence in a string. if you can delete zero or more characters to get this word then you should print "YES" else print "NO". Can anyone help

Tags: algorithm
• ## Find what number it used to be before element reset2018-11-28

Given an array with any size, in my case the array size is 5. This array contains ALL numbers from 1 to 5 (must contain all of them) [1 | 2 | 3 | 4 | 5] 0 1 2 3 4 And now, one element was reset and was set to 0, and the mission is to find what number

Tags: algorithm, java, arrays
• ## How to use the BFS algorithm to keep only the outer points?2018-10-28

Let's say I have a 500x500 2D grid (from -250 to 250). Each cell of the grid has a certain value, from 0 to 100. What I've been trying to do is keep a list of all the cell with a value lower than 50 starting at the point (0, 0), but I would like not

Tags: algorithm, path finding, bfs
• ## An auxiliary data structure required to improve performance of the application2018-09-11

I have a requirement in one of my J2EE project, where I have to pre-process data based on some business logic and formulate it into data structure (may be in memory database table) so I can use result by keeping look up into that data structure for p

Tags: algorithm, java, data structures
• ## Find sum from combination of array elements 2018-08-30

This question already has an answer here: Algorithm: Extract subset based on property sum 4 answers I have an array such as below: int[] numberArray = {9,2,1,5,6}; I want to devise a method that will take an integer as an argument and return true/fal

Tags: algorithm, java, sum

I'm writing a program that reads a general HTML "article" page (Wikipedia, NY Times, Yahoo News, ect). From that page I want to strip away all of the "noise" (ads, header bars.. anything that isn't part of the article content.) To thin

• ## Multiple sequential string replacement between two indices2018-07-22

I have a long string 'str' and a list of a triplets in the form [start, end, replace_str]. I need to iterate through the list of triplets and replace the contents of 'str' between start and end indices by replace_str. The replace_str string can be of

Tags: algorithm, javascript, string, replace
• ## Why are my nested for loops taking so long to compute?2018-07-18

I have a code that generates all of the possible combinations of 4 integers between 0 and 36. This will be 37^4 numbers = 1874161. My code is written in MATLAB: i=0; for a = 0:36 for b= 0:36 for c = 0:36 for d = 0:36 i=i+1; combination(i,:) = [a,b,c,

Tags: algorithm, big o, matlab, time, nested loops
• ## How to group close addresses?2018-06-27

I need to group addresses given their distances. Let's say I have a list of 8 addresses. 5 in NYC and 3 in New Jersey. From those 5 in NYC 3 are close to the MET and 2 to the WTC. Those 3 in NJ would form one group, those close to the MET another and

• ## Segmentation fault in LIS solution for Cracking the Coding interview 11.72018-05-31

There was a problem in cracking the coding interview -part V Question 11.7 and the solution I am trying to implement here is their solution in Java converted to C++.But I am facing issue of segmentation fault. #include<iostream> #include<vector&g

• ## How to find if two or more texts are correlated2018-05-06

Say we have two english texts T1 and T2 (disjoint no overlap ) cut out from a larger text T. Is there a way to figure out that T1 and T2 came from a single larger text? For example , newspaper layout is in multi column text. Given two column of text

Tags: algorithm, nlp
• ## Reduce a string using grammar-like rules2018-04-17

I'm trying to find a suitable DP algorithm for simplifying a string. For example I have a string a b a b and a list of rules a b -> b a b -> c b a -> a c c -> b The purpose is to get all single chars that can be received from the given string

• ## How can I iterate through all possible grid layouts?2018-03-10

I have a grid (an NSArray of CGPoints)where I want to layout some objects at points based on some constraints. This is what I know: How big the grid is The number of objects that have to be laid out on the grid, at a point The minimum distance betwee

Tags: algorithm, combinatorics
• ## Peg Solitare Recusion solution2018-02-13

Everyone knows of the cracker barrel triangle peg solitare game. You take one peg and jump it over another into an empty hole and the goal is to have only one peg left. In my code for the game board object I have a function sCpeg(int a, int b) which

Tags: algorithm, search, recursion
• ## Why isnt my program printing out what i want it to?2018-01-23

When I run my code my out put is this ----jGRASP exec: java AgeClientFL Enter birth day: 5 Enter birth month: 5 Enter birth year: 5 Birth: 5/5/5 Today: 1/1/0 Age: 0 Michaels Birth: 5/7/1995 Milestone: 5/7/2016 Age at Milestone: 0 ----jGRASP: operatio

Tags: algorithm, java
• ## what is algorithm to undirected connected graph to biconnected graph by adding edges?2018-01-22

I have a non directed graph that is connected. I want to make it bi-connected by adding minimum number of edges. How can i do it? I tried searching online for this particular algorithm and also tried thinking myself without success. Please help me un

Tags: algorithm