Discover your dream Career
For Recruiters

5 difficult Java coding problems you might find in a bank interview

Answering questions on Leetcode in preparation for a job interview is really just a roll of the dice. There's so many of them, and you can never truly predict what's going to be asked. Sometimes you might get lucky and be asked a question with an 80% success rate, other times... not so much.

We've compiled five interview questions asked by the top investment banks (Goldman Sachs, Morgan Stanley and JPMorgan) that all have acceptance rates below 50%. Solving them makes you, therefore, above average. In the case of some of these questions, well above. 

#239 - Sliding Window Maximum (Hard)

1.7 Million Submissions - 46.2% success rate

The sliding window function appears a tough concept to grasp, or at least master. You are given an array of integers and can see them only through a sliding door of size k, while only being able to see a finite number of integers at one time, it asks you to "return the max sliding window."

Where many appear to take issue with the question is the vagueness of it. Of course, in an interview the wording will likely be changed and you can't guarantee it will be easily understandable. This question is a good example of how simpler questions might be turned difficult by the way they are framed.

Think you know what it's asking for? The top comment says the goal is to show the maximum element from each window.

You can see the top ranked solution in Java here

#76 - Minimum Window Substring (Hard)

2.5 million submissions - 41% success rate

Another use of the sliding window, another question with a poor acceptance rate. This one differs in that here you are manipulating a string rather than an array.

The string gives you two strings of seperate lengths and asks you to return the minimum window substring of one string so that each character of the second is present in it. As an example, if the first string were ADOBECODEBANC and the second were ABC, the answer would be BANC.

You can see one of the top ranked Java solutions here.

#79 - Word Search (Medium)

3.2 million submissions - 40.3% success rate

Proof that the hard tag doesn't necessarily encompass the hardest problems, Word Search has proved a tricky ask for 6 out of 10 coders. Operating more like boggle than a traditional word search, the program checks if a word can be made by sequentially adding characters from the grid where each cell is horizontally or vertically adjacent.

These are some helpful diagrams for when the output is true vs when its false:

 

The key to standing out in this challenge is not just to make a solution that works, but one that can find the answer in a timely manner.

You can find the top voted solution in Java here.

#5 Longest Palindromic Substring (Medium)

7.5 million submissions - 32.4% success rate

Now we start getting into the serious questions and this one is one of the oldest on Leetcode. Longest palindromic substring asks that you search through a string of characters for palindromes, words that read the same front and back, and display the largest possible one that could be made. 

For example, in BABAD, BAB (or ABA) is the longest palindrome. In RACECAR, the longest palindrome is... RACECAR

You can see the top ranked Java solution here.

#10 - Regular Expression Matching (Hard)

2.9 million submissions - 28% success rate

One of the hardest you're likely to come across is the dynamic programming challenge of regular expression matching. It asks that you run through a string with an input pattern to see if that pattern is matches. So, for example the string AA would not match the pattern A as it is not a complete match. 

There are additional tags that complicate things however, if the pattern has a "." next to a character it asks that the string contain a single character of that type. If the pattern has a "*", it is asking that there be one or more of the character. For example, if we changed the pattern of the previous test from A to A*, the string AA would return a positive result now.

You can see the top ranked Java solution here.

Click here to create a profile on eFinancialCareers. Comment ANONYMOUSLY on articles and make yourself visible to recruiters hiring for top jobs in technology and finance. 

Have a confidential story, tip, or comment you’d like to share? Contact: alex.mcmurray@efinancialcareers.com in the first instance. 

Bear with us if you leave a comment at the bottom of this article: all our comments are moderated by human beings. Sometimes these humans might be asleep, or away from their desks, so it may take a while for your comment to appear. Eventually it will – unless it’s offensive or libelous (in which case it won’t.)

author-card-avatar
AUTHORAlex McMurray Editor
  • Do
    DoubtingThomas
    9 June 2023

    And once you pass the interview you then get to work in fixing pieces of code that are 10 years old and needed because a friend of the head of trading still likes using that software.

Sign up to Morning Coffee!

Coffee mug

The essential daily roundup of news and analysis read by everyone from senior bankers and traders to new recruits.

Boost your career

Find thousands of job opportunities by signing up to eFinancialCareers today.
Recommended Articles
Recommended Jobs
Paritas Recruitment - Data & Tech
Lead Dotnet Developer
Paritas Recruitment - Data & Tech
London, United Kingdom
Man Group plc
Java Execution Developer
Man Group plc
London, United Kingdom
Oxford Knight
Java Developer - London- Prop Trading
Oxford Knight
London, United Kingdom
Circle Square Talent
VP - Digital Infrastructure team - Leading tech M&A IB
Circle Square Talent
London, United Kingdom

Sign up to Morning Coffee!

Coffee mug

The essential daily roundup of news and analysis read by everyone from senior bankers and traders to new recruits.