Skip to main content

All Questions

-1 votes
3 answers
169 views

Why isn't my method working for finding value of Fibonacci sequence for nth term?

I am trying to find the value of a Fibonacci sequence given an integer N, representing the nth term using an ArrayList (my logic is that because ArrayList are dynamic and can resize no matter what ...
websterweb40's user avatar
-2 votes
1 answer
47 views

Maximize sum of last three remaining elements [closed]

You are given an array containing n elements, where n is odd. In one operation, you can select an index i, such that 1 ≤ i < n and remove ai and ai+1 from the array and concatenate the remaining ...
20BCS029-Ishtiyak Ahmad Khan's user avatar
0 votes
0 answers
84 views

pySpark: how to create a dynamic map from an array [duplicate]

I have a dataframe with marks in each subject and favourite_subjects. The data look like this: data = [ (1, 85, 90, 78, 88, 92, 75, 80, ["Math", "Science"]), (2, 70, 95, 82, 79,...
Data2024's user avatar
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. ...
isuf's user avatar
  • 51
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 ...
Shane's user avatar
  • 3
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 ...
Bober02's user avatar
  • 15.4k
0 votes
2 answers
85 views

why ArrayIndexOutOfBoundsException is occurring?

def change(amount: Int, coins: Array[Int]): Int = { val dp = Array[Int](amount + 1) dp(0) = 1 for { coin <- coins i <- coin to amount } dp(...
anil's user avatar
  • 1
0 votes
2 answers
70 views

dynamic programming: (minimum days of not eating icecreams)

Minimum Days Not Eating Ice-cream Ram decides to eat ice-cream for N days. On each day the ice-cream shop can have chocolate flavour or mango flavour or both or none. The availability of ice-cream ...
Srinivasan A's user avatar
1 vote
1 answer
324 views

Is there a optimal solution for Jump Game Problem using C programming

PROBLEM DESCRIPTION You are given an integer array. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position. Return ...
Mohamed Afsal's user avatar
1 vote
3 answers
93 views

Update every nth element of given a range

I have N=12 and between 1 to 12 (in N) I want every 3 elements to be updated. For example: I am calculating the current hour(say 6am) and add 4 hours to start with "6-10" for the 1st 3 rows ...
devi's user avatar
  • 33
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 ...
Bharat Reddy's user avatar
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 ...
user23374150's user avatar
0 votes
1 answer
2k views

arrays A and B of integer numbers of length N, find the maximum value on an optimal path from A[0] to B[-1]

I'm working on a problem where I have two 1D arrays, A and B, each of length N. I need to find the maximum value of an optimal path from A[0] to B[-1], moving only right or down in a 2xN grid. Here's ...
bar dj's user avatar
  • 1
1 vote
1 answer
269 views

DP array 0th element is initialized as 1 instead of 0

I encountered the LeetCode climbStairs problem: You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb ...
Hari Prasad's user avatar
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 ...
qpexxtt's user avatar
  • 21

15 30 50 per page
1
2 3 4 5
24