All Questions
151 questions
2
votes
2
answers
598
views
Find max in-order difference in array
Given an array A of integers, find the maximum of j - i subjected to the constraint of ...
3
votes
1
answer
604
views
3Sum LeetCode problem coding challenge
LeetCode 3Sum problem:
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the ...
2
votes
2
answers
247
views
LeetCode Wildcard Matching with DFS and FSM
I'm trying to solve Wildcard Matching on LeetCode. I found a great solution using the Finite-state machine. The author builds an FSM and searches with BFS.
I rewrite the solution with the same idea (...
4
votes
1
answer
140
views
Efficient polynomial multiplication in Python
I'm practicing problems for the ICPC competition, and one of the problems requires solving it by using an FFT to compute the product of two polynomials efficiently. Since this is for the ICPC ...
8
votes
3
answers
294
views
Refactor the code which performs "cross-product", "reduce", "product of list" and "sum of list"
I have come up with a sequence of steps to find the maximum product of y positive numbers which add up to x. But the program is ...
2
votes
1
answer
98
views
HackerRank Algorithm Problem: Climbing the Leaderboard (Python)
Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this?
...
2
votes
2
answers
348
views
Finding the nth ugly number
I'm trying to optimize my solution to this LeetCode problem:
Write a program to find the nth super ugly number.
Super ugly numbers are positive numbers whose all prime factors are in
the ...
2
votes
1
answer
4k
views
The smallest positive number that is evenly divisible by all of the numbers from 1 to 20
Problem description:
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of ...
4
votes
1
answer
1k
views
Given an integer array A and a range, find a subarray within the range with a minimum sum
Problem
HackerRank Range query:
You are given an array A of n integers. You have to perform ...
3
votes
1
answer
363
views
Python function to find the count of digits of numerals in base n up to a given limit
This is a simple exercise to find the count of digits of all numerals in a given base up to a given limit (not including the limit), I wrote it to determine the ratio of bytes saved when the numbers ...
7
votes
2
answers
1k
views
Find all combinations of length 3 whose sum is divisible by a given number
I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size.
The problem: Given a list ...
1
vote
2
answers
1k
views
Simplest possible Tic Tac Toe AI in Python
Last week I challenged myself to create the smallest possible code for a Tic Tac Toe game with an AI as opponent. Smallest possible in regards to say least number of characters used. The requirements ...
1
vote
2
answers
718
views
Find the cheapest flight to reach from source to destination
As the input you get the flight schedule as an array, each element of which is the price of a direct flight between 2 cities ...
8
votes
1
answer
3k
views
Project Euler 407: Is there any more optimal way to solve this idempotent equation (modulo n ring)?
Project Euler problem 407:
If we calculate a2 mod 6 for 0 ≤ a ≤ 5 we get: 0, 1, 4, 3, 4, 1.
The largest value of a such that a2 mod 6 = a is 4.
Let's call M(n) the largest value of a < n ...
6
votes
1
answer
751
views
LFU Cache implementation in Python 3
Need some feedback on this implementation of LFU cache in python3.
Original problem : https://leetcode.com/problems/lfu-cache/
Would really appreciate some feedback on readability, understandability ...