We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Could you explain the code please?
I got up to here but I dont take into account g games so not sure what Im missing as I pass the first test case but fail others.
def twoStacks(maxSum, a, b):
score = 0
counter = 0
selectig the smallest top of stack from a, and b doesn't always guarantee the maxmum number of selections. I know this seems counter-intuitive but consider the following example:
maxSum = 10
a = [5, 6]
b = [6, 4]
The correct answer is 2 selections (b[0] + b[1] = 6 + 4 = 10). But you code will produce only 1 selection (a[0] = 5).
Although I get why its working, I feel that conceptually its misleading to talk about stacks. Technically you can only view the top of item of a stack or peek at without removing it but basically the solution is that you can peek at all the values if you want and then decide which values to remove.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Game of Two Stacks
You are viewing a single comment's thread. Return to all comments →
Could you explain the code please? I got up to here but I dont take into account g games so not sure what Im missing as I pass the first test case but fail others.
def twoStacks(maxSum, a, b): score = 0 counter = 0
selectig the smallest top of stack from a, and b doesn't always guarantee the maxmum number of selections. I know this seems counter-intuitive but consider the following example: maxSum = 10 a = [5, 6] b = [6, 4]
The correct answer is 2 selections (b[0] + b[1] = 6 + 4 = 10). But you code will produce only 1 selection (a[0] = 5).
Nice one
Although I get why its working, I feel that conceptually its misleading to talk about stacks. Technically you can only view the top of item of a stack or peek at without removing it but basically the solution is that you can peek at all the values if you want and then decide which values to remove.