Wednesday, November 21, 2018

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 to print the following:
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
This is a rather straightforward problem. The solution is uploaded in my GitHub. One loop prints from 1 to 10 and the second loop prints from 9 to 1.

Problem 5:
Write a function to print the duplicate elements.
The solution is uploaded here. It takes an array as argument and prints the elements that occur twice in the argument array.
First I save the length of the array in a variable using the length attribute of the array. This attribute comes in handy in many programming problems.
Then I use a 2-step nested loop. The outer loop traverses through the first n-1 elements and the inner loop start from i+1 (the next element of the one indicated by the outer loop) and loops till the end of the array.
Here for each element pointed by a[j], it's compared with the element indicated by the outer loop a[i].  If they are equal, a duplicate has been detected and the element printed.
Take note that if the outer loop ends at the nth element instead of (n-1)th element, there'll be index out of bound error.
Problem 6:
Write a function to read integer values from a file and then print their sum.
I have uploaded a sample txt file for testing the function along with my solution.
Lines 9, 10 and 11 of the solution open a txt file named sum.txt.  Note I have used a class named File to access the txt file.
In the while loop, a line is read using the Scanner class's nextLine() method. hasNextLine() checks if there is any line left to read from the file. The nextLine() returns the integer value as a string. Integer.parseInt() converts that string to an integer. The integer value is then added to the sum variable.
After reading and summing all the numbers from the file, the sum variable is returned.
Points to note:

  1. sum variable is initialized to 0. If you forget to initialize it with 0, it may return garbage value. 
  2. You need to keep in mind how txt files are accessed, read and written to. Though this may not be needed in programming contests, you may be asked to use file access codes in interviews like this one.
  3. Conversion from integer to string and vice versa is used in many programming problems. They are also needed interview questions, as shown here.




So these were the 6 coding problems. In the next part, we'll discuss the 2 'error detection in code' problems. Don't forget to share and follow!!!

Note: The series starts from Part 1.

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.


Thursday, November 1, 2018

Interview Questions at Enosis(Part 1)

I see many people asking questions about programming interview experience. I thought I should share mine. I hope students who recently graduated from varsity will find this helpful. Though I share my experience as applying for Bangladeshi companies, I think people anywhere around the world can relate to this.

After I finished my last term at varsity, I started looking for jobs. I applied in some IT/CS companies and Enosis Solutions is one of them. Their recruitment process consists 3 steps: written exam, coding test and viva.

I will talk about written exam and coding test in my blog. At first the applicants have to sit for a written exam. Only those who were selected due to their performance in written exam, can sit for the coding test. The written exam is divided into 4 parts:

  1. Mathematics
  2. Writing codes
  3. Detecting errors
  4.  UI improvement

Mathematics:There were 4 questions from mathematics.

  1. Given a picture of rectangular box/cuboid along with the size of its sides, you have to determine the length of the diagonal. 
    Cuboid
    Cuboid
    For the given diagram of a cuboid, the length of the diagonal is: 
      __________
     H2+ B2+L2 
    As you can see, this is a simple geometry problem. We've all learned these stuff when we were in high school or college. Basic geometry questions related to the area of surface of geometry shapes(circle, square, rectangle etc.), volume of objects(cuboid, sphere, cones, cylinders) etc.
    can also be given. Most remember these formulas after learning them in high school or college.
       
  2. Jane's age multiplied by 5 is equal to Beth's age multiplied by 8. The difference between their ages is 5. Determine their ages.
    Solution:
    Let, Jane's age = x and Beth's age = y
    So, 5x = 8y
    From this equation we see, Jane is older than Beth. So, we can write: x-y = 5.
    If we solve these 2 equations, we get our answers.
    Jane is nearly 13 years old and Beth is nearly 8 years old.
  3. In one day a frog travels 3 feet upward of  a slimy wall and slides 2 feet down due to slime. How many days will it take to traverse a 30 feet wall?
    Solution:
    In one day the frog's upward is speed is (3-2)=1 feet/day. So it'll take 27 takes to traverse 27 feet of the wall. However on the 28th day, the frog at first leaps 3 feet and reaches the top( it completes traversing the 30 feet wall). Thus the answer is 28 days. 
  4. The rent of a building is fixed. If 36 people have to pay, each person pays 12 dollars more than the case where there are 40 people in the building. What's the cost per person when there are 36 people in the building ?
    Solution:
    Let, cost per person (in the case of 40 persons) = x
    and the cost per person(in the case of 36 persons) = x+12
    Since the cost is fixed, 40x = 36(x+12)
    The value of x is 108. So our answer is 108+12 = 120 dollars.
These 4 questions were given in the mathematics section. As you can see, they are quite easy. You can answer them using intuition and what you learned when you were in school. It requires simple knowledge on geometry and algebra. I don't think you'd need any prior preparation answering these questions. In the next part I will discuss the questions about writing codes.

Part 2 is HERE!!




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...