# algorithm's questions - English 1answer

3.329 algorithm questions.

### 3 Comparing Dijkstra's SSSP algorithm against Bellman-Ford in Java

Single source shortest path In SSSP, we choose a node \\$s\\$ and we compute all the shortest path starting from \\$s\\$ towards all other nodes, thus computing a shortest path tree. Two most classical ...

### 2 Solving the Burst Balloon problem using Dynamic Programming

Continuing where I left off previously to solve the problem described here, I've now solved the same using dynamic programming (following Tikhon Jelvis blog on DP). To refresh, the challenge is to ...

### Maximum number of unique integers

I'm given N integers. I need to find the maximum number of unique integers among all the possible contiguous subarrays of size M. ...

### 4 Naive implementation of Burst Balloon

As part of learning Haskell, I'm solving few problems, usually solved imperatively. I've come up with a naive solution for the problem described here, which is to find a sequence in which to burst a ...

### 3 Compression/decompression using Huffman Coding Algorithm

0 answers, 28 views c++ beginner algorithm tree compression
I am writing a program that compresses and decompresses data using the Huffman Coding algorithm. About compression: this program will export 2 files: header file (contains characters' frequency for ...

1 answers, 86 views algorithm vba excel
My idea is to make some testing system for functions, as per the model of CodeForces or TopCoder, but in VBA. There, the users write functions for a problem and the problems are tested vs. predefined ...

### -4 Sum all multiples of 3 or 5 in a given range [on hold]

0 answers, 36 views algorithm c time-limit-exceeded
...

### 1 Picking from a list of individuals based on their fitness values

I have this method that takes a list of my individuals (class has public field fitnessValue). I sum all fitnessValue and then ...

### 6 Sparse matrix compressed sparse row (CSR) in Python 2.7

Brief introduction for CSR: The compressed sparse row (CSR) or compressed row storage (CRS) format represents a matrix M by three (one-dimensional) arrays, that respectively contain nonzero ...

### 5 Encryption program for a messenger app [duplicate]

2 answers, 224 views python algorithm cryptography
I am building an encryption program for a messenger app I am developing. I was wondering if the code looks clean and succinct, and at the same times is safe and secure: ...

### 4 Longest substring in alphabetical order

3 answers, 254 views python beginner algorithm strings python-3.x
The code is meant to find the longest substring that is in alphabetical order. I would like to know if I can do it more efficiently than I have done here. I am in my first week of my first ...

### 4 Implemnting a Trie Data structures problem from HackerRank using Python3

3 answers, 89 views python algorithm python-3.x
I'm trying to write a better code in python. I don't know where to start checking. I want to make sure that I do write a best practice code. This is the second problem in Hackerrank trie data ...

### 5 Finding the longest substring in alphabetical order

I wrote code in Python that takes a string s as input and determines the longest substring of s that’s in alphabetical order. In ...

### 2 Greedy algorithm for calculating student exam schedule

1 answers, 77 views java algorithm
I decided to solve a problem posted on Stack Overflow as a bit of fun. (I wouldn't post it there as they should attempt it themselves) The basic idea is to find the exam schedule which uses the ...

### 10 Bounding volume hierarchy

1 answers, 294 views algorithm go collision
I'm building a bounding volume hierarchy in Golang. I can tell my code works because I did some test on it and it gives the same results as the brute force implementation (brute force is to test all ...

### 7 Python AVL Tree

1 answers, 874 views python beginner algorithm python-3.x tree
I decided to implement some data structures- this time an AVL tree. I think the logic is correct. Is there a way to make it clearer and do you have any ideas about more tests to add? ...

### 2 Tic Tac Toe game becomes more inefficient as time goes on

0 answers, 59 views java performance algorithm tic-tac-toe ai
I designed a tic tac toe using 4 classes. The game class being the main class, the board class being the board, the player class being the decision making, and the AI class keeping the previous game ...

I have a binary tree below and it seems to make sense to overload the insert() method. If insert() is called without a ...

...

### 6 Using range minimal query for lowest common ancestor (LCA) — part 2

1 answers, 187 views python algorithm python-2.7 tree
Here is my code to use range minimal query to resolve the LCA problem. I applied comments from here. Any advice on code bugs, performance improvement in terms of algorithm time complexity, code style ...

### 3 SPOJ Emoticon challenge

I tried this spoj problem and solved it using Dynamic Programming, but I was getting Time Limit Exceeded. The challenge is to count the number of occurrences of the subsequence "KEK" in each input ...

### 6 Compute Gregorian year from given number of days since day zero

1 answers, 247 views performance algorithm datetime batch
I am working on a batch file for doing date/time maths. One challenge is to determine the (proleptic) Gregorian year from the given number of days that have elapsed since day zero (that is, 1st of ...

### 5 Knapsack algorithm in JavaScript - Integer weights and values

1 answers, 822 views javascript algorithm knapsack-problem
My version of Knapsack works only when the weights or values of items are whole numbers. Restrictions You are given an array of objects each of which contains a weight and value. You are also given ...

### Ensuring performance of sketching/streaming algorithm (countSketch)

1 answers, 18 views python algorithm numpy stream scipy
I have implemented what is know as a countSketch in python (page 17: https://arxiv.org/pdf/1411.4357.pdf) but my implementation is currently lacking in performance. The algorithm is to compute the ...

### 1 Combine 2 overlapping rectangles

This is my solution to find the combination of 2 overlapped rectangles implemented in JavaScript. rectangle is presented by 2 points(x,y). Can this code be improved? ...

### 7 Python Prefix Notation Evaluater

2 answers, 368 views python algorithm python-3.x parsing
I'm designing a new esoteric language, and the interpreter is in Python3. It is going to use Prefix Notation, so as part of the interpreter, I need a function that evaluates a string as prefix ...

### 4 Backtracking solver for n queens problem and knight's tour

0 answers, 81 views algorithm f# chess backtracking n-queens
Playing with https://ocaml.org/learn/tutorials/99problems.html#Miscellaneous-Problems I wrote a backtracking solver for the n queens problem, then the knight's tour, and realised I could generalise ...

### Binary search for integers

2 answers, 127 views java algorithm recursion binary-search
I've written binary search with only my own efforts 💪💪 without glancing at anywhere. I stuck on finding base case. At final, I think that if last checking is less than first index or first checking ...

### 1 Recursive merge-sort inversion count algorithm very slow

I am trying to implement a recursive count of inversions in a list of integers by using merge sort and counting the number of split inversions on each recursion. My code works but runs painfully ...

### 6 Efficiently selecting spatially distributed weighted points

0 answers, 80 views python algorithm numpy opencv
Background: Motivation behind writing the following code is originated in the area of computer vision. More specifically – image rectification. In order to obtain rectified images, one has to find a ...

### Duplicating an array

1 answers, 53 views javascript algorithm array
This code returns an array that consists of two copies of the input array. Can you review this algorithm? ...

### 4 Interpreting strings with C-style escapes

2 answers, 71 views algorithm c strings escaping
I am working on a compiler that does a pretty heavy work on strings in order to get them correctly displayed. So far I have an algorithm that transforms a given string like (In plaintext): ...

### 4 Compare Strings

You have been given two strings, A and B (of length N each) and Q queries. The strings contain only 0s and/or 1s. For every query, you are given an index i. You have to update the value at ...

### 9 Determine added, removed and kept items between two lists

2 answers, 674 views python algorithm python-3.x iterator
My code is determining the difference between two iterables in terms of items that have been addded, removed and kept. The items are assumed to be sortable and there are no duplicates. ...

### 2 Finding the maximum GCD of all pairs

The code below is for Hackerrank competition. Seems that it works correctly but performs very slowly and because of it can't pass some tests. The task is to find the maximum GCD of all possible pairs ...

### Implementation of Dijkstra with adjacency list and priority queue in Ruby

0 answers, 25 views algorithm ruby graph
...

### 11 Multiplying big numbers using Karatsuba's method

The Karatsuba algorithm, first published in 1962, aims to speed up the multiplication of big numbers by reducing the number of 'single-digit-multiplications' involved. Because of its complexity (...

### Setup ordering in priority blocking queue

1 answers, 69 views java algorithm priority-queue
I have a PriorityBlockingQueue in which I am adding SocketHolder. And let's say current datacenter where this code is running is ...

### 2 Heap Sort Implementation in Python

Objective: Create a heap sort that returns a unsorted list to sorted from greatest to least. Does this implementation look correct? Do you have any tips for optimizing this? ...

### 16 Find easter on any given year

4 answers, 3.513 views c# algorithm datetime
To find the days off for our custom accounting software there is this method used to find when is Easter in any given year. ...

### 4 Implementing a 7-3-1 check digit

1 answers, 37 views php algorithm checksum
I need to implement a method that adds a "7-3-1" check digit to my id. The "7-3-1" method works as following: Weights 7, 3, 1 are assigned to the original number from right to left. So if the ...

### 4 Cracking the coding interview 1.7 - Rotate matrix by 90 degrees

2 answers, 96 views python algorithm
The question asks to rotate an image/matrix by 90 degrees. Ideally it asks to do it in place but before that I decided to do it using extra space because this is my first time working with matrices. ...

### -3 Given two sequences of integers, count the minimum number of swaps (A[k], B[k]) needed to make both sequences increasing

0 answers, 37 views c# algorithm array
You have two sequences A and B consisting of integers, both of length N, and you would like them to be (strictly) increasing, i.e. for each K (0 ≤ K < N − 1), A[K] < A[K + 1] and B[K] < B[K + ...

### -2 Longest Geometric Progression [on hold]

0 answers, 59 views python algorithm
I saw the below question on geeksforgeeks.org Given a set of numbers, find the Length of the Longest Geometrix Progression (LLGP) in it. The common ratio of GP must be an integer. Can someone ...

### 2 Generating a string in a particular format by reading data from a map

2 answers, 142 views java performance algorithm guava
I have a processToTaskIdHolder Map which contains processId as the key and taskId as the ...

### 7 Python methods to reduce running times KTNS algorithm

I have been trying to develop an algorithm called keep the tool needed soonest (for more information about the KTNS explanation (page 3)) but during the simulations, I have realized that it takes too ...

### 5 Simple parenthesis removal - JavaScript

I solved the following problem: You will be given a mathematical string and your task will be to remove all braces as follows: ...

### 6 Hash-optimization and Wilson-maze generation algorithm

I've finished optimization of Wilson algorithm (maze generation) from "silly and slow" algorithm of choosing unvisited cells: ...

### 1 Intersection of the interval set

Recently I had an interview where it was asked: Given a list of people with their birth and end years find the year with the most number of people alive. I implemented in Java and was trying to find ...

### 6 Finding the largest repeating substring

2 answers, 4.332 views python algorithm strings regex complexity
Here's my code that takes a large string, and searches for the longest reoccurring substring. It compares the first letter with every other until it finds a match, then saves it. Then it compares the ...