# Interview Questions ## Questions on GIT 1. Suppose you have a project which is hosted on github. You need to make some changes in one file within that project say a.py. What steps/commands will you take to do this? Assume the project is not in your local. 2. When you run the command `git status` you will see some file names in red, some in green. What does these color symbolise. (Follow up: There are 2 sections which show up red. Can you name what each of them stand for? ) 3. What do you know about branches in git and command to create a branch. 4. Let us consider a situation where you and your friend are collaborating on a project. You both have 2 different branches for features you are working on. Before you could merge your branch your friend has merged his. So in this situation how will you successfully merge your branch? 5. Let us consider a situation where you and your friend are working on master branch of the project that you have hosted on github. You were working on something and in the meantime your friend has pushed some changes to master. He calls you and informs you that these changes are necessary for what you are working on. How will you go ahead in this situation. (Note: You have to make sure that the changes you made cannot be discarded and you have not made any commits locally) (answer: either stash or rebase) 6. Difference between git rebase and git merge 7. What does git merge do? 8. Suppose I committed changes I made in a particular file. Later I realised that in the commit message there is a typo. Is it possible to correct this error?( If yes how?) 9. What is the difference between git fetch and git pull? If possible explain it interms of commits that happens locally. (Ans: git pull makes a merge commit but git fetch just pulls the code and saves it in .git ) 10. Command Trivia: `git merge ` What does this command do? 11. Command Trivia: `git checkout -b feature_branch` What does this command do? 12. Command Trivia: `git checkout -b feature_branch dev_branch` What does this command do? 13. Command Trivia: `git commit --amend` What does this command do? 14. Command Trivia: `git diff --staged origin/master` What does this command do? 15. True/False: If you remove a file locally(i.e right click and `delete`) can git recognise this?(followup: same with adding a file) 16. True/False: If there is a file marked red when I run the command `git status`. After I run `git commit` will it still be shown as red or not? (followup: same with green color marked files) 17. True/False: If I delete .git folder locally in your project repository then the folder cannot use git commands --- ## Questions on SQL 1. What is the order of execution for the following sql query (Solution: https://sqlbolt.com/lesson/select_queries_order_of_execution) Select col1, col2 from table1 where <condition> groupby col1 having <condition> orderby col2; 2. What is the order of execution for the following sql query (Solution: https://sqlbolt.com/lesson/select_queries_order_of_execution) Select distinct col1, col2 from table1 where <condition> groupby col1 having <condition> orderby col2; 3. What is the order of execution for the following sql query (Solution: https://sqlbolt.com/lesson/select_queries_order_of_execution) Select distinct col1, col2 from table1 join table2 on table1.col1 = table2.col1 where <condition> groupby col1 having <condition> orderby col2; 4. What code is better?(Note: We can draw 3 tables such that join on table2 and table3 will yield only 1 row) Select col1, col2 from table1 as A, table2 as B, table3 as C where A.col1 = B.col1 and B.col1 = C.col1; or select col1, col2 from (table1 join table2 on table1.col1 = table2.col1) join table3 on table3.col1 = table3.col1; 5. Design question: You and your team are building a messaging platform like whatsapp. You are responsible for database design. What tables will you need?(Note: The table needs to handle multiple groups, each group info, each student info) 1. If I want to see all messages of a particular user from a particular group, write sql command to do this. [Easy] 2. Assume each message has timestamp, if I want to see all messages from a particular group in descending order of time(i.e latest message uptop and first message at the end), write sql command to do this. [Easy] 3. Assume each message has timestamps. I want see the latest message from each group. How would you do this?[Medium] 4. I want see names of all the users who have put more than 10 messages in a particular group. How would you do this?[Medium] 5. Assume each message has timestamps. I want see the first message sent in each group. How would you do this?[Hard] 6. I want see the top 10 frequent messagers in a particular group. How would you do this?[Very Hard] 6. Design question: You and your team are building an employment portal. There are 2 types of users, company and users. The portal works the following way, company posts job application and users apply for it. {table are as shown} 1. If I want to see all the `application-id`s that a particular user has applied for. write sql command to do this. [Easy] 2. If I want to see all the `user-id`s for a particular application in descending order of time(i.e latest applied user uptop and first user at the end), write sql command to do this. [Easy] 3. I want see the latest `user-id`s for each application. How would you do this?[Medium] 4. I want see names of all the users who have put more than 1 application for a particular `application-id`. How would you do this?[Medium] 5. I want see names of all the users who have put 0 application for a particular job opening. How would you do this?[Medium] 6. I want see the first application sent for each job opening. How would you do this?[Hard] 7. Design question: You are building a comments section for an app say zomato. You are responsible for database design. The comments are nested, meaning each comment will have children comments and they inturn will have children comments. What tables will you need? 8. Design question: You are building a Question and Answering forum. The requirement is that for each question a user can give more than 1 answer. He can further justify his answer by giving subanswers and it goes on. Simply to put, 1 question will have m answers , each answer will have n sub-answers and so on. How will you design tables for this situation? 9. Explain what is join? 1. Is it necessary to have common column for joining two tables? If not does join work? 2. I have 2 tables table1 and table2. I perform three types of joins INNER JOIN, LEFT JOIN and OUTER JOIN. Can you give me the relation between count of rows in each of the results (ans: inner_join <= Left Join <= Outer Join) --- ## Questions on Python 1. True/False: Is this valid code in python? class Tree: class Node: <some class definition> <some class definition> (Follow up: Is it possible to use this definition outside the class, Ans: Yes. you can do obj = Tree.Node()) 2. True/False: Is it possible to move, copy and delete files from python? 3. True/False: Is it possible to use functions defined in another file in the current python file? If yes how? 4. Subjective: `arr = [0]*10` , what is this code doing? 5. Subjective: `arr = arr[::-1]` , what is this code doing? 6. Subjective: In class definition we see functions like `__init__` and `__str__`, what do they do? 7. Subjective: Can you explain how error handling is done in python? 8. Subjective: Asking what each of the things in this code mean class Student(User): def __init__(self,a,b=10): self.a = a self.b = b def get_sum(self): return self.__get_sum__() def __get_sum__(self): return self.a + self.b 9. Subjective: There are two ways of creating list , [] or list(). Are both of these same? 10. Major differences between c (or c++ or java) and python --- ## Questions on algorithms 1. You are given a list of n-1 integers and these integers are in the range of 1 to n. There are no duplicates in the list. One of the integers is missing in the list. Write an efficient code to find the missing integer.(Solution: https://www.geeksforgeeks.org/find-the-missing-number/#:~:text=Approach%3A%20The%20length%20of%20the,value%20of%20the%20missing%20element.) [Easy] 2. You are given a list of n integers. All numbers except one are repeated twice. Your task is to find the number which is not repeated(Solution: XOR of all number(O(1) space) or you can also use dictionary and maintain count(needs extra space))[Easy] 3. Given an expression string exp, write a program to examine whether the pairs and the orders of “{“, “}”, “(“, “)”, “[“, “]” are correct in exp. (Solution: https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/ )[Easy] 4. Design a snake and ladder game using data-structure(s) which seems suitable to you. [Easy] 5. Given an array of n integers and a number x, find the pair in array whose sum is equal to x(Followup: What if the array is sorted?)(Solution:https://www.geeksforgeeks.org/given-sorted-array-number-x-find-pair-array-whose-sum-closest-x/)[Easy] 6. A student studies for placement by solving problems the following way. First day he/she should solve 1 problem, for the following days he/she should solve twice the problem they had to solve the previous day. The catch here is that he/she can either solve or not solve the question(s) allocated for any particular day. If I give you number of problems solved can you tell me the days on which the student studied. (Example: If x=5, the student solved 1 on 1st day, did not solve questions on 2nd day, solved 4 questions on 3rd day) (Solution: Binary representation of the number)[Easy] 7. Given a positive integer, write a function to find if it is a power of two or not.(Solution: https://www.geeksforgeeks.org/program-to-find-whether-a-no-is-power-of-two/)[Easy] 8. Write a function to check whether two given strings are anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “abcd” and “dabc” are an anagram of each other.(Solution: https://www.geeksforgeeks.org/check-whether-two-strings-are-anagram-of-each-other/#:~:text=Method%202%20(Count%20characters)&text=Initialize%20all%20values%20in%20count,are%20same%2C%20then%20return%20true)[Easy] 9. Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k. (Note: Array can contain negative values)(Solution: https://leetcode.com/problems/subarray-sum-equals-k/)[Medium] 10. Given the arrival and departure times of all trains that reach a railway station, the task is to find the minimum number of platforms required for the railway station so that no train waits. (Solution: https://www.geeksforgeeks.org/minimum-number-platforms-required-railwaybus-station/)[Medium] 11. There are two singly linked lists in a system. By some programming error, the end node of one of the linked list got linked to the second list, forming an inverted Y shaped list. Write a program to get the point where two linked list merge. (Solution: https://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-lists/)[Medium] 12. Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.(Solution: https://www.geeksforgeeks.org/trapping-rain-water/)[Hard] 13. Given an infinite board of cells. Only 1 cell is active at t=1. At every timestamp each cell activates all its neighbouring cells(no diagonal cells are activated). Given `n` can you count how many cells will be active at time t=`n`(Solution: 2*(n-1)*(n-1) + 2n - 1 (on simplification: 2n(n-1)+1 ))[Hard]