 # [Community Puzzle] Bank Robbers

I’m currently doing the Bank robbers puzzle. My success rate at the moment is 75%. The only test I fail on is the “Big Heist” test, where I get 6473750. The right answer is 6515625. I’m simply looping through the array, taking only the Rth (R is the number of robbers) elements and summing them to get the total time.

Is anyone else getting similar results. I pass the all three test cases without any issues. Since the “Big Heist” case is just the “fewer robbers than vaults” but with a larger dataset I don’t see where I’m going wrong.

update:

It’s been a few months since I solved this but I forgot to post why I was failing “Big Heist”. The problem was due to me sorting the times before calculating the duration. The solution I had only worked when the times are sorted, so I scrapped that one.

tl;dr

Do not sort the times. If you do you will get 6473750.

What do you mean by “taking only the Rth elements”? Which vaults have you assigned to each robber in the “Big Heist” test case?

Are u sure the robbers work on the safe in the correct order ? i had a similar problem and it was my logic, i wasn’t looping on the correct thing kinda x) but i had a number that was bigger than the expected one, on your side it’s the other way around … but maybe u’ll think about something !

gl & hf This problem is not linear. You have to think about what happens, for example, when one robber goes through 3 rounds of unlocking while other robber is still stuck in the first round.

PS. hit me a message if you need an idea codewise.

Hi I got the same problem, and I want to figure it out. Can you help me a little ?

I also get 6473750. and 75 %

Had the same problem, getting the same value Finally, re-re-re-reread the statement and got it ! “index” is the key 1 Like

This problem is not linear. You have to think about what happens, for example, when one robber goes through 3 rounds of unlocking while other robber is still stuck in the first round.

How could that happen, knowing that all robbers will try all combination at same speed on their vaults ?
“He tries all the possible combinations, i.e. he continues to try the untried combinations even after he has found the correct combination.” I really don’t get the idea of this puzzle ^^’

Hi,
I have a problem with Bank Robbers puzzle. All tests pass but not “submision tests”. I would love to know why. I found several solutions where second test didnt passed and finaly I found solution without any way of anything hardcoded but last 2 dont pass now (reminder - in IDE all tests pass).
In last hours I exhausted all ideas of what could possibly go wrong, but it feels like som bug.
I would appeciate some feedback on this. Cheers!

My code:
class Solution {

``````    public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int R = in.nextInt();
int V = in.nextInt();
List<Integer> combs = new ArrayList<>();
for (int i = 0; i < V; i++) {
int C = in.nextInt();
int N = in.nextInt();
}

int count = 0;
while(!combs.isEmpty()) {
count++;
for (int j = 0; j < R; j++) {
if(j<combs.size()) combs.set(j,combs.get(j)-1);
}
for (int k =0; k < combs.size(); k++) {
if(combs.get(k) == 0) combs.remove(k);
}
}

System.out.println(count);
}
}``````
2 Likes

Hi,

you’re program is too slow, you’re only decreasing combs value by one each iteration.

Hello!
Dosnt sounds right. This slightly different solution (pasting bellow) passes all “submit” tests exept second one so it feels weird, that if its fast enought for big heist, that its slow for second test. More so, my other, even slower solution which is way slower than this one passed all tests. But I hate that accepted solution, its ugly and indeed slow. I dont understand why this slution cant pass.

``````class Solution {

public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int R = in.nextInt();
int V = in.nextInt();
List<Integer> combs = new ArrayList<>();
for (int i = 0; i < V; i++) {
int C = in.nextInt();
int N = in.nextInt();
}

int count = 0;
while(!combs.isEmpty()) {
count++;
for (int j = 0; j < R; j++) {
if(j<combs.size()) {
combs.set(j,combs.get(j)-1);
if(combs.get(j)== 0)
combs.remove(j);
}
}
}
if(R>1) count--;

System.out.println(count);
}
}``````

Well I tested the first code you provided and indeed it timed out. Maybe it was not too slow but anyway it timed out.
The second code you provide do not timeout but is off by one on the second validator.

I don’t know Java but if you use this while loop and remove the “if(R>1) count–;” it works:

``````    while(!combs.isEmpty()) {
count++;
for (int j = 0; j < R; j++) {
if(j<combs.size()) {
combs.set(j,combs.get(j)-1);
}
}
combs.removeIf(s -> s == 0);
}``````

Hi, your solution works and I cant really find any difference from mine exept that in yours is used removeIf lambda, yet still your solution passes and mine not. Probably some Java related thing which is beyond my knowledge scope. Because my for cycle and your removeIf should do exactly the same, isnt it?
I dont know, its so hard to do any testing if tests in IDE are different from “submit”. I understand protection from hard-coders, but if there is no hardcode and it passes in IDE, then it shuld be fine… Or at least if submit tests give some feedback.
I have absolutely no idea how to improve in this puzzle with this kind of behavior and testing Anyway, thank you for checking it out.
Cheers,
Petr

2 Likes

Get to level 29 and then you’ll see the validators for the training puzzles Aha, so one have to go blind and is alowed to see once he gets to where is seeing not relevant anymore, how esoteric But thank you, good to know.
cheers

anyone had already solved the big heist problem? I can’t seem to understand the said logic:

“Once he finishes one vault, he moves on to the next vault of greater index (robbers work the vaults in increasing order) which nobody has worked on yet”

Hi.

I trying to solve the puzzle but can’t even calculate the example:

``````Input
1
1
3 1
``````

Here is my solution:

``````// the password: 1 digit + 2 chars (3 - 1)
// count of possible digits = 10 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// count of possible chars = 5 ['A', 'E', 'I', 'O', 'U']
time_for_digits = 10^1 = 10
time_for_chars = 5^2 + 5^1 = 30
time_total = 10 * 30 = 300
``````

But the right answer is 250.

Need some hints…

Nope, error here.

Your are right. Wrong formula. I got it, thank you.