These Problems Will Ask In Your Next Interview: Problem-Solving Questions and Answers

Geno Tech
Geno Tech
Apr 16 · 4 min read

Ready for your next tech interview today #4

Problem-solving is a compulsory skill you have as a professional in the Technological field. It is testing during your interview process. If you succeed in this challenge, you have the extra potential to get your new job. Because most of the developers are only able to do traditional tasks, but they fail to solve problems. Another problem is the lack of resources to learn about these problems. Sometimes very expensive, Sometimes have no enough clarifications and answers. Also, you need to practise these questions day by day, that’s the way you have to develop this skill. There have other advantages also. This series of stories make it easy at your next interview. This is also very useful in every position for you as a Software Engineer/Developer, Senior Software Engineer, Tech Lead, Full-Stack Developer, Data Scientist etc.

Let’s go to the first question. Every Problem has a specific order to follow as follows.

  • Description of the question
  • Our answer in Java
  • Explanation.

We are ready to accept any question regarding these problems you have.

Question #1: Birthday Cake Candles

You are in charge of the cake for a child’s birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

For example, the integer array, “candles” is shown below:

The maximum height candles are units high. There are of them, so return 2.

  • Solution (In Java)

For example, the square matrix arr is shown below:

  • Explanation

In every problem, It’s important to see the whole problem as tiny steps. That’s the easiest way to solve any problem. On this problem, first, we need to find the maximum of the List. Then need to find how many elements represent that value in the List. so In my solution, We can find the maximum of a List like follows.

Then I have found the number of maximums represents in the List using a for a loop.

Question #2: Pairs of Socks

  • Problem

There is a large pile of socks that must be paired by colour. Given an array of integers representing the colour of each sock, determine how many pairs of socks with matching colours there are.

  • Solution(In Java)
  • Explanation

First of all, you want to divide the problem into pieces. That’s the way to solve the problem in an easy manner. Here we need a for loop to get numbers one by one. then we check the number has met before. If not, we can check how many numbers belongs to that particular number.

Question #3: Creating a Magic Square

  • Problem

We define a magic square to be an n*n matrix of distinct positive integers from to where the sum of every column, row, or diagonal of length is always equal to the same number that’s called the magic number.

You will be given a 3*3 matrix ‘arr’ of integers in the inclusive range [1,9]. We can convert any digit a to any other digit b in the range [1,9] at cost of |a-b|. Given arr, convert it into a magic square at a minimal cost. Print this cost as the result.

  • Solution(In Java)
  • Explanation

It takes a bit of pen and paper to see that, the magic constant is equal to the 15. How you get it?. The sum of 1 to 9 is 45 and when we divide it by 3, we can get the magic sum is equal to 15.

Also, the middle value is always equal to 5. Then we can find that the numbers 2,4,6,8 are always positioning at corners and the numbers 1,3,5,7 are at the other four places respectively. This is the secret behind this story, you have to identify. Finally, you can found only 8 possible ways in which matrices can arrange.

Therefore in this solution, you need to create an array to store all possible solutions which we recognized previously, and we can calculate costs for all those solutions. Then the final result is the minimum cost.

The thinking part of this problem is very important to other matrix problems. Hopefully, this is enough explanation for this problem.


This story solved another three interview questions you will face in your next interview. Hopefully, you have enjoyed it. Please feel free to ask any question you will face in the response section below. Also, ask any other related questions you have.
Happy Coding !!!!
Found this post useful? Kindly tap the 👏 button below! :)

App Dev Community

This is for Mobile App Developer to exploring and sharing the knowledge.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store