All Questions
16 questions
1
vote
2
answers
1k
views
Leetcode 55. Jump Game solution
I was working on Jump Game problem on leetcode
Question
You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your ...
3
votes
4
answers
194
views
Is this an efficient/correct way to get largest Prime factor?
Is this an efficient way to get the largest prime factor of a given number? Other solutions I found involved nested algorithms.
...
4
votes
1
answer
728
views
Performant Sort function for big arrays
In sort(arr), I want to sort an array. Children must be beneath their parent. And children of the same parent are sorted using ...
1
vote
1
answer
111
views
Form the largest number by swapping one pair of digits
You are given a number. You are given the opportunity to swap only once to produce the largest number.
My approach was to use buckets whose values were their indexes and their locations were their ...
0
votes
1
answer
884
views
Iteratively determine the diameter of a binary tree
Can the performance of the iterative approach be improved? I find that this approach lags behind many recursive options. no recursive answers, please.
Baseline recursive approach: takes 52 steps ...
3
votes
1
answer
2k
views
JavaScript Determine if Number is Lucky
A challenge from Code Fights; a function that takes a number no less than 10 and that will always have an even number of digits and determines if the sum of the first half of the digits equals the sum ...
1
vote
1
answer
632
views
Year with the most living (given a list of births and deaths)
I am trying to find the year most people are alive, given a list of births and deaths. I am not sure my approach is optimal or if am calculating the time complexity correctly
Break down:
I sort the ...
2
votes
2
answers
2k
views
Determine if Array has an Increasing Sequence
I wrote a function in JavaScript that expects an array of integers (negative or positive) and determines if that array has an increasing sequence.
For the sake of better time performance I made the ...
3
votes
2
answers
3k
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 ...
5
votes
2
answers
2k
views
JavaScript function for finding perfect numbers
The following function has been created for finding "Perfect Numbers".
About Perfect Numbers: Wikipedia
...
0
votes
1
answer
12k
views
Complexities: Filtering out nested array inside an array
I am doing some iteration over an array which have another set of array (the nested array). I need to .map() the outer array in such a way that it should filter out ...
4
votes
1
answer
1k
views
Calculating binary tree height as asked in the interview
Input:
The first line contains the number of vertices \$n\$. The second line
contains \$n\$ integer numbers from the range \$\left[−1, n − 1\right]\$ representing the \$0\$-based index of the ...
3
votes
1
answer
605
views
Stack which finds the minimum element
Write a program to implement stack which implements min a method
which gives the minimum element below the top element in the stack.
...
2
votes
1
answer
2k
views
Finding the sum closest to a target number
Wallace the Weightlifting Walrus is training for a contest where it will have to lift 1000 kg. Wallace has some weight plates lying around, possibly of different weights, and its goal is to add some ...
2
votes
4
answers
289
views
Long arithmetic addition in JS
The implementation of the algorithm which adds two number in string form with arithmetic rules.
...