algorithm's questions - English 1answer

3.429 algorithm questions.

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

Problem Description The objective is to form the maximum possible time in the HH:MM:SS format using any six of nine given single digits (not necessarily distinct) Given a set of nine ...

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 ...

Leetcode problem 279 “Perfect Squares” is: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) I wrote the following solution: ...

Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j]. If there is no solution possible, return 0. Example : A : [3 5 4 2] Output : 2 for the pair ...

I'm working on a crypt-arithmetic solver to add two or more numbers. I've used brute-force to find all the permutations. I'm looking forward to improve this algorithm. Kindly review for all the ...

This is a program that uses the Quine McCluskey algorithm to simplify user inputted minterms. This is the main ...

You can find the problem here. The example: Column A, B, and C are each 3 and together equal 9: ...

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 ...

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 ...

The problem statement: Take a set of numbers as input, find the power set. Find the subsets with equal sum. These subsets should be disjoint. I am supposed to use the brute force technique for ...

This is a recursive approach using DFS to counting the number of islands. However, I would like to improve performance, while keeping the code clean concise and readable. Better yet can this be solved ...

I have the following concise-ish (and working) approach to getting all the forward permutations of a list of string. So with the list: w = ["Vehicula", "Sem", "Risus", "Tortor"] the results ...

I have implemented my solution and I thought it was pretty efficient and passes most of the cases but seems like it fails some of the test cases when the input size is very large. I basically push ...

Here's my attempt at a C++2a Standard Library–friendly "topological sort" algorithm. There are several areas of interest here: The algorithm is comparison-based and in-place, just like ...

I want to go more in depth, but this is the 'boilerplate'. Is there any way I can optimize this or use more idiomatic Python code? ...

This is a follow-up question for HackerRank - Array Manipulation Problem You are given a list (1-indexed) of size \$n\$, initialized with zeroes. You have to perform \$m\$ operations on the ...

This is my implementation for this hacker rank problem. (And a follow-up.) Problem You are given a list(1-indexed) of size n, initialized with zeroes. You have to perform m operations on the ...

I have been unsuccessfully trying to adapt this solution "Balanced parentheses" at Code Review SE to be able to check if the quotes and parentheses are balanced. For example this should be unbalanced ...

You will be given an integer k and a list of integers. Count the number of distinct valid pair of integers (a,b) in the list for which a+k=b. For example, the array [1,1,1,2] has two different ...

I came across problem 54 on projecteuler.net and decided to give it a go using ReactJS. I have had Angular experience prior to this. I wrote a couple of fully tested components. I think that they only ...

I've written a very simple linked list based stack implementation and was wondering if this is the standard way to do it in C. ...

I have been trying to solve this question. Given an unordered array consisting of consecutive integers [1, 2, 3, …, n], find the minimum number of two-element swaps to sort the array. I was able ...

I am doing a college assignment where I have to count the number of inversions in an array/list. An inversion is defined as a tuple where i<j and a[i]>a[j]. ...

I was solving this problem for implementing LinkedList and ListNode classes, and Insert and <...

...

Given an array of integers, find the longest consecutive sequence, where a sequence is defined as being either (strictly) ascending, (strictly) descending, or all-equal. 836926 then has the longest ...

I implemented the Shunting-yard algorithm in Python, I have experience in C# but I'm looking for comments making this more pythonic. I'm also be interested if these methods would be better as ...

I created a BFS algorithm in order to solve an 8-puzzle, and while it works, it is awfully slow compared to my DFS implementation. My main point of concern is the puzzleExists() function, which ...

I have implemented travelling salesman problem using genetic algorithm. Since project is not so small I will give short introduction.GeneticAlgorithmParameters - ...

I'm working on this kata from Codewars. The task is: Given a certain number, how many multiples of three could you obtain with its digits? Supose that you have the number 362. The numbers that ...

Problem: We are interested in triangles that have integer length sides, all of which are between minLength and maxLength, ...

I have following task, form a given array, I want the longest ascending array. I will give you an example int[] a = {19,12,13,1,2,3,4,5,14,23,24,25,26,31,32};...

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Example one: Input: [7,1,5,3,6,4] ...

Array A contains the elements, \$A_1,A_2, \ldots, A_N\$. And array B contains the elements, \$B_1,B_2, \ldots, B_N\$. There is a relationship between \$A_i\$ and \$B_i\$: any element \$A_i\$ ...

I have been trying to solve this simple problem on SPOJ for quite some time now, but I keep on getting TLE (Time limit exceeded) for some reason. Since the problem is in Portuguese, a brief ...

I have a processToTaskIdHolder Map which contains processId as the key and taskId as the ...

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

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 ...

The task is to return array with values which satisfy the condition: for each max the less or equal numbers count. Example Input: numbers = [1, 2, 1, 4] maxes = [2, 4]. Output: [3, 4] Explanation =...

Problem : A binary tree is given as an input, each node of binary tree contains one integer value. Find the maximum sum of collection of nodes such that following two conditions are met. if node's ...

I have a huge array that I want to group by by category and subcategory. A Book is contained in a shelve. A Shelve is contained in a Library. The output is a list of Library. I cannot change my Book ...

I wrote this function to map value to a color I am looking for some general feedback on how I can improve the efficiency of the function. and if there is better way to do it. ...

I written code to solve this problem which I found on leetcode. My solution worked for the vast majority of the test cases run against it but failed on 2 for some reason. The first test case it failed ...

...

The problem that this is based on is something like the following: A matchmaker is working with six clients: John, Joe, Charlie, Jill, Leslie, and Katie. John is compatible with Jill and Leslie, ...

I'm trying to see if someone can come up with a better solution for this algorithm. I have an input of three lists/queues and I have to group/sort the elements of ...

Find all pairs in an array that sum to a given number without using HashMap. Duplicate pairs are not allowed. Input array cannot be modified. input: ...

This is my first algorithm in C++ ever to check if two strings are permutations of each other. Please provide guidance on correctness of algorithm + ways to improve + thoughts on my use of the ...

Here is the question: find the largest palindrome from a string. Ex:ABCBAHELLOHOWRACECARAREYOUILOVEUEVOLIIAMAIDOINGGOODResult: ...

Related tags

Hot questions

Language

Popular Tags