## 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
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!!

## Wednesday, October 24, 2018

### Beginner's Guide: Some Useful Machine Learning Websites(Part 2)

In the previous tutorial (Part 1) I've talked about adventures-in-machine-learning.com. Today I will talk about another online resource that comes in handy when one needs to quickly implement neural network models without going through all the hassle of the theories. As a result, I recommend this AFTER you've gone through the articles in  adventures-in-machine-learning.com. So, today we're going to talk about python-programming-dot-net.

When I was doing my thesis, I at first went through the theories and step by step implementation  in adventures-in-machine-learning.com. When I had a better grasp about the topics in neural networks, I started following this website. They have tutorials on various topics. But I'm going to focus on machine learning tutorial which starts from this link.

Here the tutorial for a particular topic( i.e. regression, neural network)  spans several articles. I found the articles fun to read and the code easier to understand(since I've already studied  adventures-in-machine-learning.com ). I recommend you implement the code in your own computer/laptop as well rather than just watching the implementation in the videos. The tutorial topics are laid below in order:

• Regression: Regression is taught in any ML course in the beginning. Many even include assignments to implement this. In my thesis I also had to use regression to figure out the relation among some variables. It also helps one to ease into ML course before moving onto more difficult topics. So definitely check it out. The vlogger notes the important points to implement this in python. So you won't miss much in the case of implementation. But I also recommend studying the theories a bit before watching the tutorial for better grasp.
 Linear regression
• The next topic is K-nearest neighbor starting from here. I only had to study the theory for my academic course. But you can check it out.
• After K-nearest neighbor comes SVM. Some of my classmates had to implement this in their thesis. So you may have to as well. SVM is also given as homework/assignment in many varsities. So this series of articles may come to your aid when you are given work to do using SVM.
• Now comes clustering. Like K-nearest neighbor, I studied the theories only so I didn't go through the articles here. I recommend you study these articles, if you have to do specific tasks in academia that requires them.
• After clustering comes deep learning tutorial in TensorFlow. This part has greatly helped me when I was just beginning to learn the implementation of neural network in Python. It begins with using a multi-layer neural network on MNIST data-set. The explanations of the codes are quite easy to understand and so very suitable for beginners. The second example is positive/negative sentiment analysis of text data. So there's one example with image data-set and one example with text data-set. Most of the data-sets, one deals with while learning machine learning, are either text data or image data. Short tutorials are also provided for Recurrent Neural Network( RNN)  and Convolutional Neural Network( CNN). RNN is used when the data samples are related to one another( sequential data) and CNN is used for image data-sets because of its efficient feature extracting abilities. Their implementations are given in TensorFlow. The implementation can be used for your academic or professional work with ease and understanding. I highly recommend you go through this section if you are interested in deep learning.
• Another important section of this website is the 'Natural Language Processing' tutorials. Many CS students, taking up machine learning courses or theses, may have to study NLP and implement NLP. Here too the website has created simple yet comprehensive tutorial to learn the implementation of NLP in Python. I do recommend some prior theoretical study before diving in. The tutorial is long but it's totally worth it!! It will let you grasp the basic coding skills you need to perform NLP-related tasks with ease. Before copy-pasting the code, do go through what the article says about its code so that you don't get confused while writing down the code.
That's it for today. These are the sources that helped me most to learn about the wonderful world of deep learning. Do let me know what you think in the comment section and follow me on Google+ to get more updates in my blog.

## Friday, October 12, 2018

### Beginner's Guide: Some Useful Machine Learning Websites(Part 1)

I have been away for quite some time now. The reason is I was quite busy with my academic thesis and general academic pressure. Now I do feel I can regularly post in my blog.

So today's topic that I choose is Machine Learning. I have done my thesis on neural networks. There were also 2 optional courses( Machine Learning and Pattern Recognition) I undertook for better understanding machine learning as a whole. Machine learning is a hot topic of research these days. All the top varsities are doing extensive studies and research on various aspects of machine learning. Some are exploring its application in real life situations while others are delving deep into the mechanisms of the algorithms.

When I first started doing my undergraduate thesis, I hardly knew anything about machine learning. As a result I had to search through internet for websites that would easily and extensively explain the basic mechanisms of machine learning, specifically neural networks.

I found 2 sources quite helpful in understanding how machine learning works and how to implement them into python code. I was able to read research papers with greater understanding after going through the contents of these 2 websites. It also helped me in my academic studies. I will describe first one for today's post.

I think before mindlessly coding for machine learning models, one must learn the theory to understand what one is actually coding. Adventures in machine learning is one of the best sources out there to introduce newbies to the vast world of machine learning. The articles also come with basic implementation of the theories. It helps greatly with both academic courses and thesis activities.

Some of the articles I had to study extensively are given below. They helped me build a strong basis in learning about machine learning for both my academic course and my thesis.

• This is the first article of this source I studied. The articles are rather large and does require quite a bit of your time and effort. For the first timers this may even seem overwhelming. So I advise you bookmark the article and read it part by part. Trying to read the whole article at once will only hurt your brain. You may feel frustrated and at the end of reading the whole article at one go you may not even learn anything. Too much information will just jumble up everything. That's why you need to read it part by part taking your time. And do read it multiple times for clear understanding. Reading it only once may not convey much information.
 Neural Network with 1 hidden layer, 2 output and 3 input nodes
• NOTE: So now you may feel exhausted reading 2 previous VERY big articles. It may take some time to both finish reading them and understanding the concepts of neural networks. But I assure you it's worth it. In academia, you always have to spend time and effort on such large and detailed articles. You may want to take some time off before moving on to other articles so that the knowledge you learned here will sit with you in future. You may also want to revise them( I suggest you do) to keep the knowledge fresh in memory.
• Improve Neural Networks: So let's dive in further into the vast world of neural networks. For beginner models you will see high performance BUT as you start learning more complex models, accuracy becomes a BIG issue. You then feel frustrated because the performance isn't improving. In most cases the reason behind low accuracy of the model for beginners can be attributed to lack of implementing some basic concepts. 2 such concepts have been included in this articles. Their definition, description and expressive implementation in python have been provided for our convenience. It also discusses about the process of choosing better variables to improve neural networks along with a step by step implementation. This article is shorter than the other 2. So hopefully, reading it won't exhaust you :p

That's it for today. In the next article (Part 2) I'm going to review another of my favorite online resource regarding neural networks.

## Wednesday, November 29, 2017

### CodeForces: Xenia and Ringroad(339B) Solution in Java for Beginners

Since this is a beginner's problem, I suggest you try it out yourself first.

Java programming topics you need to have knowledge of ->

.
.
.
.
.

Explanation of Solution:

After taking the necessary input in an array (the house numbers), we assign the variable result (the total time) a[0] - 1: this is the time to go to the 1st house (from house 1 to that house).

We enter a for loop now to traverse all the houses/array elements one by one. In each iteration, if the current element/house number under consideration is greater than the element before, it is in front of the previous house. In this case, we just add the difference of the house numbers.
In the 'else' case, we see the house number is less than the previous one meaning we go to that house after completing the rotation. So we apply the rotational equation n - (a[i-1] - a[i]).
Accumulating the results like this, we get our final solution.

## Friday, September 1, 2017

### Data Structures: Dynamic Array implementation in C++ (Part 1)

What is array?
-->Often, we have to deal with groups of objects of same type such as names of persons, instrument readings in an experiment, roll numbers of students, and so on. These groups can be conveniently represented as elements of arrays. An array is defined as a sequence of objects of the same data type. All the elements of an array are either of type int (whole numbers), or all of them are of type char, or all of them are of floating decimal point type, etc. An array cannot have a mixture of different data types as its elements. Also, array elements cannot be functions; however, they may be pointers to functions. In computer memory, array elements are stored in a sequence of adjacent memory blocks. Since all the elements of an array are of same data type, the memory blocks allocated to elements of an array are also of same size. Each element of an array occupies one block of memory. The size of memory blocks allocated depends on the data type.

Here's a youtube video to understand the concept of Array : Intro into Arrays

In this post, we are going to look at the C++ implementation of Array meaning , we will write the code for several functions to manipulate an Array. By successfully understanding these functions , we will know how an array works.

Each Computer Science student must do an obligatory course on Data Structures. During this course , the students come across the implementation of many data structures. Arrays list implementation usually comes in the beginning of the course. So this is one of the easier data structures to both understand and implement.

We are going to complete 6 tasks to create a complete code to manipulate an array list. This code will be helpful in teaching you guys to manually make your own code for data structures. Such codes are needed in the future in situations where custom made array list codes are needed. After the 6 tasks (mentioned below), I will show you an example to implement this code to solve a problem.

Task 1: Add getLength function. Add a new function getLength to the list. This function will return the current length, i.e., the number of items, of the list.

Task 2: Add insertItemAt function. Add a new function insertItemAt to the list. This function will insert a new item at a given position. The prototype of the function is as follows: int insertItemAt(int pos, int item). The function will insert the given at the given position . You have to do this by shifting only one item of the existing list. Note that the pos value can be larger or equal to length variable. In such a case, you should not insert anything in the list. You may also require allocating new memory similar to insertItem  function if list is already full.

Task 3: Add shrink feature to the list. The current implementation expands its memory when it is full. This is done in the insert function. When it finds that the length variable has reached the value of listMaxSize, it allocates a new memory whose size is double the existing memory. Your job is to add shrink feature to the list. This feature will allow the list to shrink its memory whenever the length variable has reached to half of the current size. In that case, you will reallocate a new memory whose size will be half the current size.
However, if the current size of the list is LIST_INIT_SIZE, then you will not need to shrink the memory. Write a function shrink that will shrink the list appropriately.

Task 4: Add deleteLast function. Add a new function deleteLast  to the list. This function will behave similar to existing deleteItem function except that it will delete the last item of the list. You will not need to move any other items. So, this function will not have any input parameter. You must call the shrink function after deletion. You will also require adding shrink function calls inside deleteItem and deleteItemAt  functions.

Task 5: Add clear function. Add a new function clear to the list. This function will delete all items from the list and will de-allocate its memory. When a new item will be inserted next, the list must be allocated a new memory of size LIST_INIT_SIZE again. You must write required codes in the insertItem  function to enable this.

Task 6: Add deleteAll function. Add a new function deleteAll to the list. This function will delete all items from the list, but will not de-allocate its memory. However, it will shrink its memory to LIST_INIT_SIZE if the list is currently consuming a memory whose size is larger than LIST_INIT_SIZE.

Before I head on to the solution, I want you guys to think about the tasks and write codes solving them. This will increase your capability to think about problem solving. I will write blog posts describing the solution in near future.

Don't forget to share and follow my blog-posts...... See you guys next time. :)

## Wednesday, August 30, 2017

### CodeForces: New Year Transportation(500 A) Solution in Java for Beginners

New Year Transportation(500 A) Problem Link

The solution is found in the problem, so I suggest you try it by yourself.
If you need a quick reminder for while loop, check out this youtube video of newBoston.
You can find a tutorial for if-else, on this tutorialspoint page about if-else.

.
.
.
.
.

New Year Transportation(500 A) Solution Link

If you are facing problems solving this,  you can come here for the solution. So after taking the necessary input, you begin from the first index (currentIndex - set to 1). Then you enter a while loop. Here on every iteration, you check whether you've reached your destination, on which case done variable will be true. If currentIndex > destination, you'll never get to destination since you can't travel backward. In this case, you just break out of the loop. The loop will terminate once you've traversed the whole array.

Finally, you check whether done is true (you've reached your destination) or false(otherwise).

Check out my other codeforces solutions under the codeforces label.

## Tuesday, August 22, 2017

### Codeforces: Pangrams 520A Solution in Java

The problem is a simple one. If you learn Java Strings, it'll be a piece of cake. I suggest you try the problem yourself before proceeding. As a quick reminder, check out this short java string tutorial from tutorialspoint  as a guide to this problem.

When taking input, in line 13 I've written an extra sc.nextline(), because when taking a string input before an integer input, omitting line 13 would cause erroneous input. So line 13 works as buffer to correctly take a string input after a numerical input.

The 'frequency' integer array will count the occurrence of each character in the input string. frequency[0] refers to  the count of 'a', frequency[1] refers to  the count of 'b' and so on. For convenience I've converted the whole string into lowercase. To determine index into this array for a particular character just subtract 'a'. For example index for count of 'c' is 2. So if we encounter 'c' just subtract 'a' from 'c' to get the index 2.

Next we check for the number of elements in the frequency array that have non-zero values. If it's 26 we output 'YES', since all the characters in the alphabet are present. Otherwise print "No".

Hope you find this useful. Check out my Hackerrank Solutions in Java. Don't forget to share and follow :)

## Monday, August 21, 2017

### CodeForces: Ultra Fast Mathematician-61A Solution in Java

The problem is a simple one. If you learn Java Strings, it'll be a piece of cake. I suggest you try the problem yourself before proceeding. As a quick reminder, check out this short java string tutorial from tutorialspoint  as a guide to this problem.

Now let's come to our solution. After taking the input, we enter a for loop with range from 0 to n-1 , where n is the length of the input string(both strings have the same length). We extract one character from each string and put them in two character variable a and b.

We now check whether they are the same character or not. If they are the same, we output 0. Otherwise, we print out 1 since a and b are not same characters.

After the loop is finished, we get the desired output binary string.

Don't forget to share and subscribe.

## Thursday, July 13, 2017

### Beginners Guide: Google Ranking. Tips for Improvement In Ranking

Page ranking by Google follows an algorithm called PageRank (PR). The purpose of this algorithm is to rank websites to display in Google search engine and use this resultant rank to order websites in that search engine to put the more popular pages to the front. The basics of the algorithm is to calculate the a website’s quality by determining the number of links of various other websites pointing to the website and also the quality of the aforementioned links. In simple mathematical terms, if a page provides quality content, it is considered more important to a wider population of internet users. As a result, it will get a higher number of links from other websites.
When Google first launched its search engine, this algorithm was used. It is the best-known algorithm so far, though other algorithms have been developed since that time.
If you want a comprehensive description and analysis of PR algorithm, check out the wikipedia page for Google PR.

For bloggers interested in SEO(search engine optimization), this term comes up sooner or later because they want to put their blog or website at the front pages of google or any other search engine. This blogpost discusses the factors to use this concept for one’s benefit i.e. to make one’s website rank higher in the search engine.

WHY Does Google Page Rank (For SEO) Matter:
Many believe Pagerank is dead- a propaganda spouted everywhere. This is incorrect. This is a very important algorithm that will always be used to rank websites. Many SEO practitioners don’t understand it well and may say it’s not important. But it would be wise not to pay heed to such ill advice. Many think so because Toolbar PageRank is indeed dead. So what is Toolbar PageRank? It is a webtool to determine the rank of a page by analysing search information from Google’s database.
It used to help SEO bloggers since the tool was updated several times but now according to this source, Google has now decided to remove this tool.  On their part it’s a considered as a ‘smart’ business decision to stop the manipulation of search results.
The real algorithm, however, is still running but the visual tool used by the bloggers is now taken out. Since the algorithms is running behind the curtain to influence the search results, it is still relevant for bloggers to pay attention to this, if they want to bring their pages forward in the search engine. Thus Google PageRank still matters, though we may not have a visual of the results.
What Should A Blogger Do To Improve Google Page Ranking:

## If you are interested in programming problem solutions, reviews of programming websites and useful articles for beginners, feel free to check out A Programmer’s Experience.

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