Skip to main content

All 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 ...
D_S_X's user avatar
  • 189
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. ...
Tharindu's user avatar
  • 143
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 ...
Helix112's user avatar
  • 143
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 ...
MadHatter's user avatar
  • 855
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 ...
se77en's user avatar
  • 85
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 ...
MadHatter's user avatar
  • 855
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. ...
kharandziuk's user avatar
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 ...
michael.zech's user avatar
  • 4,814
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 ...
Rick's user avatar
  • 586
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 ...
Rick's user avatar
  • 586
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 ...
Aman's user avatar
  • 141
4 votes
3 answers
2k views

Removing duplicates from an array

I recently wrote this JavaScript algorithm for removing duplicates from an array as part of a job interview process, but was turned down for the position after submitting the code. I didn't receive ...
jmknoll's user avatar
  • 141
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 ...
CodeYogi's user avatar
  • 5,137
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 ...
Rick's user avatar
  • 586
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 ...
Solomon Ayoola's user avatar

15 30 50 per page