Tuesday, November 6, 2018

Interview Questions at Enosis(Part 2)

In Part 1 I've discussed the mathematical questions. In this part, I will discuss the codes, I had to write down. There were 6 questions in total which tells you to solve a coding problem and write down the code. You can use any either C++, Java or Python to answer each question. The problems given here are usually encountered, if we practice the beginner's problems in various. Do check my article about some great websites to practice programming.

Problem 1:
Write a function to reverse a string.
In Java/Python there are built-in functions to do this task. But it's common many might not remember that. Same goes for me. I also thought they wanted to check out my skills at using loops and character array. So, I decided to use loops to reverse a string.
I recommend you try it out yourself first and then see my solution.
In the answer script you only need to write the 'reverse_string' function. The main function is coded by me to check whether I made any mistakes or not. Since you have no choice of testing your written code in a computer, you need to be careful what you write.
Points of caution:

  1. Check whether the function return type matches what you write in the return statement.
  2. Check the conditions of the loop function and think whether they can cause any error. The loop starts from the last index, ends in the first index and it's decremented for this problem. If you're writing down code without getting a chance to test it, making silly mistakes in the for loop conditions is quite common.
For this problem notice I used length() and charAt() functions. It means you need to remember some basic functions of programming language like print, scan, length of array/string, some string operations, reading/writing from/to txt files etc.


Problem 2:
Write a function to reverse a sentence.
If you check out my solution, you'll see it's quite similar to the 'reverse' method of problem 1. The main difference is you need to create an array of words first and add those words in the 'reverse' variable one by one in the reverse order. Notice I use a 'split' function to break up a sentence string to an array of strings. Also notice I use a length attribute to determine the length of the word array. If you practice some simple programming problems, learning these tricks won't be difficult at all.

Problem 3:
Write a function that prints all the multiples of 3 from 200 to 1.
I think this is the easiest problem of the bunch. I strongly recommend you write the method yourself at first.
Here is my solution. Silly mistake to be noted here is that you may write only one equal sign instead of 2 in the if condition statement. As always do double check whether you've written the conditions in the for statements correctly.

With these 3 problems I conclude this part. In the next part I'll discuss the other 3 coding problems. So share and follow. If you've got queries feel free to comment.


No comments:

Post a Comment

Interview Questions at Enosis(Part 3)

In Part 2 , I have discussed 3 coding problems out of 6. Here we will talk about the next 3 coding problems. Problem 4: Write a function...