All Questions
200 questions
0
votes
4
answers
275
views
Max sum when in each step selecting one addend, then removing last and first element
I have an array. Each iteration, I take an element from the array and add it to a running sum. Then, the first and last element are discarded. I cannot pick an element in the same initial index twice.
...
0
votes
0
answers
70
views
Select top K arrays in an array of arrays, that will consist of the most unique elements
Given an array of arrays, with each sub-array contains unique elements, but among different sub-arrays, there might be the same element. Select the top K sub-arrays, that the union of all elements ...
0
votes
1
answer
299
views
Effective hiking - dynamic programming
I got the following question today, and solved it suboptimally. I wanted to get some help how to get this to the most optimal solution:
The question is; A hiker needs to complete a lit of trails on ...
3
votes
1
answer
1k
views
Minimize sum of products of adjacent elements of an array
Given an array of n integers, arr, rearrange them so that the following equation is minimized.
sigma i=0 to n-1, arr[i]*arr[i+1]
Examples:
n=7
arr=1,10,2,7,10,6,6
Answer: 127 (optimal arrangement is ...
1
vote
2
answers
1k
views
Pick K letters to build as many strings as possible
I stumbled upon this question and I'm unable to solve it. Any help is much appreciated.
You are given an array S made of N strings and an integer K. Choose at most K letters from the alphabet that ...
0
votes
0
answers
236
views
Find n indices such that their sum is equal to k, and the sum of the elements at these indices is minimal
You are given n arrays. Each consists of non-negative integers in ascending order. You need to find n indices such that their sum is equal to k, and the sum of the elements in these arrays at the ...
2
votes
3
answers
3k
views
Minimize array elements by multiplying adjacent elements only if the product is less than equal to k
I recently came across this question in an online assessment.
arr = [2,6,2,4]
k = 15
The array elements need to be minimized by multiplying two adjacent elements only and only if their product is ...
2
votes
3
answers
566
views
Coin change problem with a condition to use exactly m coints
I have coins for 10, 30 and 50. But I want to use only M coins to get a given sum.
I have this code (from this as reference) that just find all possible ways to get the total sum without applying the ...
0
votes
1
answer
919
views
Minimum of maximums for k-size nonconsecutive subsequence of array
Suppose I have an array, arr = [2, 3, 5, 9] and k = 2. I am supposed to find subsequences of length k such that no two elements in each subsequence are adjacent. Then find the maximums of those ...
-5
votes
1
answer
142
views
Find good days to rob the bank - some test cases failing
I came across the LeetCode problem 2100. Find Good Days to Rob the Bank:
You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] ...
0
votes
1
answer
689
views
Divide an array into k parts to minimize the difference between (max of each part * num of elements)
Given an array arr and a partition value k, I need to divide it into k parts such that the difference between the product of maximum value of each part times number of values in each part is minimized....
0
votes
2
answers
439
views
How to regroup into two arrays with equal sum?
I encountered a question that I couldn't solve during my algorithm interview. The question goes:
Given an array of length n, where n is an even number, regroup the elements in the array into two ...
4
votes
1
answer
2k
views
Maximum & Minimum of any subarray in constant time
I am a computer science engineering student and I came to this problem in many tasks.
I am given an array of size with values and then asked a number of queries .
In each query I am given two ...
-1
votes
1
answer
584
views
Understanding the solution of cloudy day problem
I was solving cloudyday problem on hackerrank:
City has many towns. p is an array of population of n towns. x is an array of location of towns on 1 dimensional array (thus a numeric location). y is ...
2
votes
4
answers
5k
views
Maximum Sum of Two Non-Overlapping Subarrays of any length
I see "Maximum Sum of Two Non-Overlapping Subarrays (of specific given lengths and the array contains only positive numbers)" from Leetcode
https://leetcode.com/problems/maximum-sum-of-two-...