{"id":8595,"date":"2019-01-07T15:38:12","date_gmt":"2019-01-07T15:38:12","guid":{"rendered":"https:\/\/www.monsterindia.com\/career-advice\/programming-interview-questions-and-answers-8595\/"},"modified":"2023-03-27T18:33:48","modified_gmt":"2023-03-27T13:03:48","slug":"programming-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/www.foundit.my\/career-advice\/programming-interview-questions-and-answers\/","title":{"rendered":"Programming Interview Questions and Answers"},"content":{"rendered":"\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\"><\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">There is no dearth of programmers and computer science graduates applying for the positions of a programmer at different levels in an organization. Big Technology giants like Amazon, Google, Microsoft are always on the lookout for programmers with in-depth knowledge in key areas. Even service-based companies like Uber, Netflix encourage talent in coding. <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">The challenge is to cruise past the most difficult interviews in these companies. Here we have put together top 15 Programming <a href=\"https:\/\/www.monsterindia.com\/career-advice\/top-100-interview-questions-to-help-you-succeed-in-a-job-interview\/\" target=\"_blank\" rel=\"noopener\">Interview Questions which may be thrown at the interview<\/a>. <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">To best address all aspects of programming, the questions must be divided into various sections: <\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">Interview Questions on Arrays <\/span><\/strong><\/span><\/h2>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">Arrays are the most frequently encountered topics in coding and there are plenty of questions that can be asked on this. Below are the most frequently asked ones: <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\"><strong>1. How will you find a missing number in an integer array of say 1-100?<\/strong> <\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">This is a common array question asked in Java, C or C# interviews. There are multiple approaches to tackling this question: <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">\u2022 You can use the formula for sum of the series which is n(n+1)\/2. But this will work only if there is one listing number. <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">\u2022 BitSet class in Java if the array has more than one missing number. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">2. In an array, there are multiple duplicate numbers. How will you find them? <\/span><\/strong><\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">The trick to approaching this question is to use Hashmap or HashTable to store the number as a key and number of occurrence as its value. If the number is already present in the table, then increment the value or insert 1. Later, print out all those numbers who have more than 1 as the value. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\"><strong>3. Given two arrays, find which number is not present in the second array.<\/strong> <\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">For this again, HashTable comes in handy. Put the elements of the second array in the HashTable. For every element in the first array, check if there is an entry in the HashTable. Output all elements of the first array that are not there in the HashTable. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">4. How will you remove duplicate elements from an array in Java? <\/span><\/strong><\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">For this, the tricky part is not just finding the duplicates but also remove them. For this you can use Collection Class unless the interviewer says specifically not to use it. You need to convert your array to an ArrayList and then create a LinkedHashSet from that ArrayList. <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">In this way, duplicates are removed from the array without copying them to a result array. <\/span><\/p>\n\n\n\n<p><strong>You may also like:&nbsp;<\/strong><a href=\"https:\/\/www.monsterindia.com\/career-advice\/10-tips-to-stay-focused-in-an-interview\/\">Tips to Stay Focused in an Interview<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">Interview Questions on Strings <\/span><\/strong><\/span><\/h2>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">String class is a key element in any programming language and there are always some questions on String variables. Some of them are: <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">1. Write code to check whether a given String is a palindrome or not <\/span><\/strong><\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">These are the steps to check if a String is a palindrome or not: <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">\u2022 Reverse the given string. <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">\u2022 Check if the reversed string is equal itself. If yes, then the string is a palindrome. The reverse(String text) method is used for the same. If the result of the reverse() method is equal to the original string, then the given string is a palindrome. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">2. How will you extract a particular character from a string? <\/span><\/strong><\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">Convert the string into a character array and then use substring() method to remove the particular character from the string. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">3. Differentiate between String, StringBuilder and StringBuffer in Java <\/span><\/strong><\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">String in Java is immutable whereas StringBuilder and StringBuffer are immutable. StringBuffer is synchronized whereas StringBuilder is not and hence used for temporary string manipulation because it\u2019s faster. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">Interview Questions on Linked List <\/span><\/strong><\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">Apart from String and Array, Linked List is another kind of data structure that is very important in any programming language. It can do whatever array cannot. Below are some common Linked List interview questions. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">1. How will you find the middle element of a Linked List in a single iteration? <\/span><\/strong><\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">The simple solution for this is to traverse the Linked List until you reach the tail that points to null, find the length of the Linked List and keep re-iterating till you reach the middle. <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">To find it in a single pass, you must use two pointers-one incrementing one step at a time while other increments two steps at a time. While one pointer reaches the end of the list, the other will point to the middle element. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\"><strong>2. How will you find out if there is a loop in a single linked list?<\/strong> <\/span><\/h3>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">This question can be answered can be solved using 2 pointers- increase one pointer one step at a time and the other one two steps at a time. This way, if a loop exists, they will meet each other at some point.\u202f <\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">Some other frequently asked Programming interview questions\u202f <\/span><\/strong><\/span><\/h2>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">For the below questions, you will need to write code or algorithm. <\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">1. How will you implement a binary search tree? <\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">2. Using quick sort, write a program to sort numbers. <\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">3. Write code to implement a binary search algorithm (in Java or C++) <\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">4. Write a program to find all prime numbers up to a certain number <\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">5. Write the algorithm to find the nth Fibonacci number in a series. <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">The key pointer in a programming interview is that the interviewer will go with the flow and ask you follow up questions based on your response. You must be sharp and attentive. While writing code, you must account for nil input, erroneous input and other checks.\u202f <\/span><\/p>\n\n\n\n<p><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">More than the exact syntax, the interviewer will rate you based on your quick response, problem-solving skills and ability to think out of the box. If you are well prepared and confident, no one can stop you from landing your dream Programming job.<\/span><\/p>\n\n\n\n<p><span style=\"font-size: 12pt\"><strong><span style=\"font-family: verdana,geneva,sans-serif\">Looking for Programming Jobs in top cities? Click at the links below:<br><\/span><\/strong><\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">\u2022&nbsp;&nbsp;<a href=\"https:\/\/www.monsterindia.com\/search\/programming-jobs-in-bengaluru-bangalore\" target=\"_blank\" rel=\"noopener\">Programming Jobs in Bangalore<\/a><\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">\u2022&nbsp; <a href=\"https:\/\/www.monsterindia.com\/search\/programming-jobs-in-mumbai\" target=\"_blank\" rel=\"noopener\">Programming Jobs in Mumbai<\/a><\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">\u2022&nbsp; <a href=\"https:\/\/www.monsterindia.com\/search\/programming-jobs-in-chennai\" target=\"_blank\" rel=\"noopener\">Programming Jobs in Chennai<\/a><\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">\u2022&nbsp; <a href=\"https:\/\/www.monsterindia.com\/search\/programming-jobs-in-gurgaon\" target=\"_blank\" rel=\"noopener\">Programming Jobs in Gurgaon<\/a><\/span><br><span style=\"font-family: verdana,geneva,sans-serif;font-size: 12pt\">\u2022&nbsp; <a href=\"https:\/\/www.monsterindia.com\/search\/programming-jobs-in-pune\" target=\"_blank\" rel=\"noopener\">Programming Jobs in Pune<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is no dearth of programmers and computer science graduates applying for the positions of a programmer at different levels in an organization. Big Technology giants like Amazon, Google, Microsoft are always on the lookout for programmers with in-depth knowledge in key areas. Even service-based companies like Uber, Netflix encourage talent in coding. The challenge [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8596,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[147],"tags":[],"class_list":{"0":"post-8595","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-interview-questions"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/posts\/8595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/comments?post=8595"}],"version-history":[{"count":2,"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/posts\/8595\/revisions"}],"predecessor-version":[{"id":16029,"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/posts\/8595\/revisions\/16029"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/media\/8596"}],"wp:attachment":[{"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/media?parent=8595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/categories?post=8595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.foundit.my\/career-advice\/wp-json\/wp\/v2\/tags?post=8595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}