All Questions
33 questions
6
votes
1
answer
347
views
Codeforces: D2. Counting Is Fun (Hard Version)
The code works okay for the following problem.
Problem
An array 𝑏 of 𝑚 non-negative integers is said to be good if all the elements of 𝑏 can be made equal to 0 using the following operation some (...
1
vote
1
answer
598
views
Leetcode: 2327. Number of People Aware of a Secret
On day 1, one person discovers a secret.
You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the ...
3
votes
1
answer
118
views
Segmentation of list to minimize the largest sum
I have written the following code for diving a list 'seq' into 'k' segments such that the maximum sum of each segment is minimized. I have used dynamic programming to solve this problem. But my class &...
3
votes
1
answer
848
views
Divide array into three disjoint sets with equal sum
Problem definition : Array partition problem
Given an array of positive integers, divide it into three disjoint subsets having equal sum. These disjoint sets cover the complete array.
Example
Input: [...
4
votes
2
answers
100
views
Unique Paths II, dynamic programming problem, O(n^2) time, O(n^2) space
This is based on this leetcode question. I get the correct answer, but I know it could be much, much cleaner. I also know there is supposed to be an O(n) space solution, but I'm not sure how to ...
1
vote
1
answer
472
views
LeetCode 1320: Minimum Distance to Type a Word Using Two Fingers II
I'm posting my Python code for LeetCode's 1320. If you have time and would like to review, please do so.
Problem
You have a keyboard layout as shown above in the XY plane, where each English uppercase ...
2
votes
1
answer
2k
views
Maximum sum combination
I am trying to solve this question: https://www.codechef.com/problems/TADELIVE
Andy and Bob are the only two delivery men of Pizza-chef store. Today,
the store received N orders. It's known that ...
5
votes
1
answer
351
views
Total number of non overlapping subsets
I am trying to solve this question. The essence of the problem is this:
Given a list of school classes with start and end times, find the total number of non-overlapping subsets.
I've written up a ...
1
vote
1
answer
598
views
Solution to knapsack problem exceeds time and RAM limits
My goal is to code the knapsack problem algorithm. The problem is that a knapsack has a given weight limit, W. I have a collection of items which have a given ...
3
votes
2
answers
641
views
Determine if a string is a sequence of dictionary words
This is Leetcode problem 139: "Wordbreak"
Problem: Given a non-empty string s and a dictionary wordDict
containing a list ...
2
votes
1
answer
82
views
Length of the longest common sub sequence bottom up
Could I get some feedback on this code? I included a test case as well.
This code computes the longest common sub sequence given paired data, it was not part of any challenge I just did it to learn ...
1
vote
3
answers
1k
views
Subarray Sum Equals K
I've written a solution to the following leetcode problem:
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.
Example ...
5
votes
3
answers
2k
views
Find smallest number of squares that sum to a number
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:
...
6
votes
3
answers
2k
views
Performance of dynamic Fibonacci generator and dead rabbits
I would like to improve my code style and its efficiency.
I'm just moving beyond the standard recursive approach to a lot of simple algorithms.
This post has two code snippets with slightly ...
8
votes
1
answer
4k
views
Minimum cost path of matrix using Python
I was reading this article about finding the minimum cost path from (0,0) to any (m,n) point in a matrix. Using python the ...