Programing/Coding Interview Questions


Introduction


This post will have most important interview Coding and analytics questions which used to ask in most of the reputed companies like Google, Amazon, NetApp, Wells Fargo etc.
We are just adding Questions to this post and the technical reader will post the answers using comments sections.
Please add your solution to help others who are preparing for an interview or enhancing their skills. Thaks a lot everyone for supporting knowledgewala.com.

 


Q1.

Given an array of sorted integers and find the closest value to the given number. Array may contain duplicate values and negative numbers.
Example:

Array: 2,5,5,6,7,8,9,9

Target Number:5
Output:5

Target Number: 11
Output: 9

Target Number: 1
Output: 2


Q2. Write a function to convert a String of ip address to hex
eg: ip is 197.27.11.11 = 0xX51BBB


Q3. A college student’s record contains the following:
1. Name
2. Age
3. Subject(s)
4. Marks
5. ID

The student can choose from English, Mathematics and History as Subjects/
A student can choose one, two or all of the subjects.

The requirement is to search for students who have scored marks more than
X in a certain subject. Which Data Structure would you use and how would you solve this problem
in an optimal manner?


Q4. Implement your own linked list?


Q5. Write a program to reveres string from intervals?


Q6. Find the maximum consecutive 1’s in an array of 0’s and 1’s.
Example:
a) 00110001001110 – Output :3 [Max num of consecutive 1’s is 3]
b) 1000010001 – Output :1 [Max num of consecutive 1’s is 1]


Q7. You are given the arrival and departure times of airplanes at an airport for a single day. Schedules for the airplanes remain the same across all days. You are to determine the number of gates the airport should have so that no plane spends time waiting for a gate.
arr = [9:30, 11:15, 16:30]
dep = [11:45, 11:30, 16:45]
Arr array is sorted by time. And departure array is sorted by corresponding arrival times. Plane ‘i’ arrives at time arr[i] and departs at time dep[i]

Notes:
After some questions, it was decided that minute was the smallest unit of time we cared about. Gate was considered occupied on the arriving minute, but empty on the departing minute. And that the arrival and departure times could be represented as such as integers. e.g. Day runs from minute 0 to minute 1339 (since using a zero-based index). So our example times represented as:
arr = [570, 675, 990]
dept = [705, 690, 1005]


Q8. Write a method to count the number of 2s between 0 and n?

Where n is positive integer.


Q9. Write a program to find distinct value out of an array. If you did not find any duplicates return an empty array.


Q10. If a=1, b=2, c=3,….z=26. Given a string, find all possible codes that string can generate. Give a count as well as print the strings.

For example:
Input: “1123”. You need to general all valid alphabet codes from this string.

Output List
aabc //a = 1, a = 1, b = 2, c = 3
kbc // since k is 11, b = 2, c= 3
alc // a = 1, l = 12, c = 3
aaw // a= 1, a =1, w= 23
kw // k = 11, w = 23


Q11. Write a program to modify the string in following pattern,
Change odd words to uppercase and Reverse the even words. Make sure that the spaces (multiple) between the words remains as it is.
E.g.:
INPUT: “This is a test String!!”
Output: “THIS si A tset STRING!!”


Q12. Write a code to find duplicate elements in an array and total count of duplicate elements.

eg. arr={5,3,4,6,7,5,3,2,1}
Duplicate elements:- 5,3
Total duplicate count:- 2


Q13. Create a restful API for user registration with following fields

  • Name
  • Email
  • Pincode

On Successful Registration, UserId will be generated.


Q14. Create a restful API to get a login for registered user.

  • Call login API with UserId
  • Send login link(http-link) to his registered email.
  • Login-link expires in 15 min.

A user opens given login-link. if login-link is valid and not expired. show user details.

  • Name
  • Email
  • Pincode

Q15. Create a restful API to get current temperature by pincode
– Use https://openweathermap.org/current API
– Save temperature-info into a database.
– If temperature-info already exist in a database and it is less than 30-sec old. Then give saved-value else refresh data (call open-weather API ) then return new value.

Question: As in step 3, Instead of showing user details. Redirect user to show current-temperature for his/her pincode (saved at registration time).
Question:. Write a schedule which updates temperature-info in a database every minute for all saved records older more than 1 minute.
Instructions
– Use whatever technology/framework suits for above requirement. But restrict to JAVA.
– Follow best practice to design/architect and coding.
– Code for all required components of app needed to fulfill above usercase. Don’t skip any important code segment.
– Also mention the tools you used for this exercise.


 

Leave a Reply

Your email address will not be published. Required fields are marked *