Interview Questions I - Neethahiremath/Wiki GitHub Wiki
- implement own hash code method without generating from IDE
- can we have same hash code for different objects - yes
- Difference between deep copy and shallow copy, implement with example
- concurrent HashMap
- implement blocking queue
- if you create fixed thread pool how many blocking queues will be used - 1 queue
- which thread pool is used by servlet (spring boot) - forkjoinPool
- If we are using JDK 8 then parallel GC is the default garbage collector.
- interface and abstract class features in java8
- if you have 10 partitions , how many max no of consumers can you have in consumer group - 10
- local QUORUM and QUORUM in cassandra - n/2+1 where n is replication facto
- consistent hashing in cassandra, diff types of hashing its using and which is default this key is hashed using murmur3 algorithm.
- v node in cassandra - sub nodes within node to divide the hash ranges.
- write data where will it write first -> SS table and MEM table in cassandra - MEM table
- why compaction is required in cassandra - read time decrease and tombtones delete, multiple SS table combine to single based on recent timestamp.
- what are tombstones, what will happen when you perform delete operation in cassandra
- cap theorem
- difference between rabit mq and kafka
- how do u get single list from multiple list using java8
- why java8 is called functional programming
- what is the rate messages are pushed and consumed in kafka - in application 2k per seconds.
- kafka is which type as part of cap theorem. Kafka is a CA system:
- what is the threshold limit of data size, producer right to the topic - 1MB
- how spring will handle the circular dependency
https://www.baeldung.com/circular-dependencies-in-spring
/*
Overloading
applicable within the class
if parameter dataType passed does not have exact match, it looks for parent dataType and call the method
It calls method based on object reference and not on object. example :
animal a = new Dog()
since a is assigned to animal, it looks for method having animal as parameter
*/
public class OverLoadingExample {
public void display(Animal a) {
System.out.print("Animal called");
}
public void display(Dog a) {
System.out.print("Dog is called");
}
public static void main(String[] args) {
OverLoadingExample testClass = new OverLoadingExample();
Animal animal = new Animal();
Animal animal1 = new Dog();
Dog dog = new Dog();
testClass.display(dog);
testClass.display(animal);
testClass.display(animal1);
}
}
public class OverRiddingExample
extends Animal{
@Override
public void display() {
System.out.print("hi");
}
public static void main(String[] args) {
Animal test = new Animal();
test.display();
/* OverRiddingExample animal = new Animal();
animal.display();*/
OverRiddingExample animal1 = new OverRiddingExample();
animal1.display();
OverRiddingExample test1 = new OverRiddingExample();
test.display();
}
}
paypall
- find the longest palindromic substring. - https://www.geeksforgeeks.org/longest-palindrome-substring-set-1/
- merge the k sorted linked list - refer coding section / https://www.techiedelight.com/efficiently-merge-k-sorted-linked-lists/
oracle:
- buy and sell the stock
- wt is docker
- wt is k8
- wt u understand by k8 for deployment
- explain about projects
- wt is the process of development to deployment followed in your project.
- sliding window of k find the max element https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
- design Notification service
- how u jvm implements synchronised
- how many jvms will be running if u run 2 instance of project
- what will happen when same jar is deployed in different servers, will hashing algo be same used by jvm for hashmap
- what happens when project runs
- list of strings, find the count of anagram pairs
- what is diff between abstract and interface
- what is diff between overloading and overriding
- can we overload the static methods
- can you override the static methods
- can we overload the main method? yes but JVM calls the original method only
- what is binary tree and construct the binary tree with given in order and postorder traversal
- why multiple inheritance is not allowed in java
- types of set and what is set data structure
Inorder - 4, 2, 1, 7, 5, 8, 3, 6 Postoder - 4, 2, 7, 8, 5, 6, 3, 1
- PermGen and metaspace difference
growOrange:
- find loop in linked-list
- wt is difference between horizontal and vertical scaling
- explain about transaction in RDBMS and how consistency is maintained
- wt u understand by distributed systems.
- how data will be distributed and wt are the challenges faced
- suppose you have a robort, trying to lift the rod, design how can u make the Robert to pick from center of the rod
Blue global:
what is static and dynamic polymorphism what is composition, aggregation what is default interface how static methods are handled in interface
guess the output:
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
// if terminator is not used streams can be modified and it impact the original streams.
// only once we can fetch the data from streams, if we try to use it again we get stream has already been operated upon or closed error
Stream<String> e1 = list.stream().filter(e -> e.equals("e"));
list.add("e");
Optional<String> any = e1.findAny();
e1.findFirst();
}
- what is dependency injection
- what are different scopes of beans
- what is difference between application scope and singleton bean
- how hash map works internally
- consider that we have a map with Employee object as key, employee has id and name as fields.
- what are the access modifiers for class : only for inner we can give private, for outer class when u declare private we get compile time error
add one to int array {1,2,3,4} out: {1,2,3,4,5}
public int[] plusOne(int[] digits) {
int i = digits.length-1;
while(i >= 0) {
if(digits[i] != 9) {
digits[i] = digits[i] + 1;
return digits;
}
digits[i] = 0;
i--;
}
int[] res = new int[digits.length + 1];
res[0] = 1;
return res;
}
walmart:
- buy and sell stock any number of times
- https://www.geeksforgeeks.org/minimum-number-of-jumps-to-reach-end-of-a-given-array/
Minaral tree: Design parking lot of 500 capacity
Myntra:
- search a node in BST
- Counting binary substrings
SalesForce:
- find the count of all possible subtrees whose sum is given
- find if linked-list is a palindrome
- max sum in subarray
- find the longest sum array
- given binary tree join the adjusent nodes
ex: 1
2 3
4 5 6 7
join 1 to null and 2->3 3 to null 4->5->6->7->null
Big Basket:
- BST tree becomes skived, to avoid the situation balancing tree
- so write a algo for self balancing tree
AJIO:
if you remove the connection of node, is it possible to get the subtree sum same, return true if yes else no
DP World:
given a binary tree, target node and distance get all nodes with given distance
Ring Central:
- merge 2 linkedlist
- given metrix of sorted column and rows, search the integer
- difference between ArrayList<>() and linkedList<>()
- explain collections of java
- guess the output:
Falabela:
- remove duplicate employee name and id combination
- Two sum problem
- different type of functional interface and its uses
Nokia:
- what is difference between hashmap and concurrent hashmap
- different design patterns used in applications
- code to sort the employee list with age
- what are functional interface
- what are new features in java8
- what is lamba expressions
- how is spring boot different from spring mvc
- explain spring architecture
- how to connect database from spring boot application
Morgan:
- write a code for printing number divisible by 3,5,7,11, and avoid the multiple if else check
- git command for merging the multiple git commit to single commit
- what is stash
- what is difference between git and GitHub
- what is difference between fetch and pull
Helofiy:
- find the next palindrome number
- find the smallest subset which has n distinct number of integers
- check if brackets are proper without using extra space
VMWare:
-
find the smallest missing integer and also duplicate number without extra space. https://www.youtube.com/watch?v=s_nYIsbPqqQ
-
sol: to find the duplicate number in an array, take the number and in its index, make the number negative and when you find the number already negative, than it means that the number is already available.
-
for smallest missing no : n*/n+1/2 is total natural number sum.find the missing by subtracting the total sum of from given integer array.
-
given two tree with left and right subtree, one tree having the name and another having the age.
-
find the age of the member in family by matching the name passed in the request.
-
find the subArray with given sum
BlackBug:
- implement LFU cache
Target:
- student heights in increasing order, print the range with frequency
152,156,158,162,168,172
o/p:
150 : 3 160: 2 170: 1
- time complexities -> what is the hierarchy for nlogn, O(n), logn logn,o(n),nlogn
modify the above scenario with solution of O(logn)
- implement the rate limitor
- what is the tps for application
- how jenkins build the image and how do you push the image to gcp
- how do you see k8 logs
- how grafana gets the matrix
American Express:
- what is different between dynamo db and hash-map
- what is difference between couch-base and cassandra
- what is internal architecture of couch-base
- design multiple Lift in a single building
- Kafka is synchronous or asynchronous
- how do you decide on partitions and concurrency - > decide based on performance test
- what is CAP theorem and y partion tolerance is important
- design patterns types:
- difference between NOSQL and SQL
- how will handle stale updates
- what is eventual consistency
- write a code for longest consecutive integers
- two frogs needs to jump far away bcz they fought, given the height of the piller
- card winning problem
- Security for restEndPoints -> explain Oath
- couchbase query called as N1QL
- two string tel if they are isomorphic
FreshWorks:
- what is rate limit and wt status code sent for this - 429
- what is 507 - > insufficient storage
- explain promotes and what time series database is used by that
- how matrix are captured by spring and provided to Prometheus
- what metric parameters are exposed by spring
- what is garbage collectors, how it knows we need to garbage collect
- how are you scaling the application
- what are the matrix for operating system
- what k8 deployment strategies used and how it does the health check
- how spinner helps in deployment to cloud
- how will you manage sudden spike
- what if cpu is not high but response time is increasing ?
- thread dump and heap dump
- how will you fine tune the sql and why do u create index.
- how does index work
LendingTechnology:
- https://www.geeksforgeeks.org/given-sorted-array-number-x-find-pair-array-whose-sum-closest-x/
- merge two intervals
MFine:
- find the product of array elements except itself
- merge the intervals
- Design Rate limiter *. Buy and sell stock 1 time
SAP:
- write unit test case for scenario
- write a custom functional interface
- write a code for jpa repository
- why you choose couch-base db
- what is difference between cassandra and couch-base
- what are different design patterns
- if you need H2 db for test class and prd different db, than use spring profile
- what is the real time example for prototype scope
- what are different types of scope
- explain spring security
- design twitter high and low level design
- coding standards
- design patterns used in application
- why SAP labs
- what module did u design and implemented urself
- what is threadLocal
- write a code to demo thread deadline and how you stop thread deadlock
- what is the CICD process used in project
- what is idempotent and non Idempotent apis
- how to make post method idempotent
- how good are you in multithreading, Executive services
- kafka purpose
- what is caching and its uses
MakeMyTrip
- MaxSubArray with equal number of as and bs
- given n number of array and k, find the k numbers with maximum frequency
- what you use for validation service
- how are you managing exception handling
- how do you make a class immutable
- how many consumers are there and how you handling auto scaling of consumers.
JPMorgan:
- what is the use of property class in java
- what is difference between abstract and interface
- how can you make class immutable
- how can you avoid multiple fields parameter constructor : use builder *how is equals and hashcode
- if you have list of lines for stock, how will you process them ex: stock name, Buy/sell, qty, price
- if you want to execute 3 task first and than 4th task depend on previous task what needs to be used in java
- explain multithreading in java
Adobe:
-
Given an m x n matrix, 0 for empty, 1 for healthy and 2 for unhealthy unhealthy makes healthy node unhealthy what is the minimum time required to make all people unhealthy. if cant be made return -1.
-
Given an m x n grid of characters board and a string word, return true if word exists in the grid.
The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighbouring. The same letter cell may not be used more than once.
Input: board = [["A","B","C","E"], ["S","F","C","S"], ["A","D","E","E"]] word = "ABCCED" Output: true
- design rate limitor https://medium.com/geekculture/system-design-basics-rate-limiter-351c09a57d14
Quizzes:
Q1 - /**
-
Given an array , you can choose a set of integers and remove all the occurrences of these integers in the array.
-
Return the minimum size of the set so that at least half of the integers of the array are removed.
Example: ORIG SIZE -> 10 Target size -> <= 5
-
Input: arr = [3,3,3,3,5,5,5,2,2,7] Arr = [ 7, 2, 2, 5, 5, 5, 3, 3, 3, 3 ]
-
Output: 2
Constraints: 1 <= arr.length <= 10^5 arr.length is even. 1 <= arr[i] <= 10^5
**/
Q2. /** We are given an array of integers representing asteroids in a row.
For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.
Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.
Example: Input: asteroids = [5,10,-15] [ 5, 10, -15 ] [ 5, -15 ] [ -15 ]
[5, -15, 10] [ -15, 10 ]
5 < 10 < -15
Output: [5,10]
Constraints: 2 <= asteroids.length <= 104 -1000 <= asteroids[i] <= 1000 asteroids[i] != 0 **/
-
design game management system. users play game and score is showed on dashboard with top 10 users.
-
design low level for below
-
Question: simple MCQ questions with 4 options and 1 correct
-
Quiz: consists of a set of questions
-
Game: started from a quiz and played by players using a pin code.
Flows:
- Creating and updating Quizzes
- User should be able to create a new quiz
- They should be able to add questions to quiz
- They should be able to remove questions from quiz
- They should be able to update any questions in that quiz
- User should be able to order the questions in the quiz Creating a game from Quiz User should be able to either use the newly created quiz or search for any quiz (created by anyone) and start a game with that quiz On creation, the game should have a unique pin that can be shared with players Pin codes needs to be 6 digits strings 1 day max limit Playing the game Players should be able to enter the unique pin of game and join the game On joining, they should be served with a set of questions (from the quiz the game is using) Players should answer these questions one by one, upon answering they are rewarded 1000 points if the response was correct, and 0 if incorrect These responses should be recorded for displaying to the teacher Displaying report A teacher should be able to view the report of a game running or completed The report should display Every players total score(dsc order) Which player got which question correct and incorrect Teacher can choose to just stop the game
Note:
-
There should be no restriction on how many games are running from a single quiz
-
There should be no restriction on the creator of quiz, they should be allowed to edit / update the quiz whenever they want, even if there are games running that are using that quiz
-
Quizzes created everyday: 50K (10 questions on avg / quiz, 500 max)
-
Games created everyday: 200K (12 players on avg, 120 answers on avg / game, 500 players max)
MetaMap:
StockX:
Implement LRU cache and basic cache:
https://medium.com/algorithm-and-datastructure/lfu-cache-in-o-1-in-java-4bac0892bdb3
design: At StockX, we have a catalog of products. On any of these products, you can place a bid (which indicates that you’re willing to buy at a certain price) or an ask (which indicates that you’re willing to sell at a certain price). Let’s imagine that we somehow didn’t have the endpoint that allows you to place bids. I’d like you to design that for me
package leetcode;
import java.util.*;
public class LFUCache {
HashMap<Integer, Integer> vals;//cache K and V
HashMap<Integer, Integer> counts;//K and counters
HashMap<Integer, LinkedHashSet<Integer>> lists;//Counter and item list
int cap;
int min = -1;
public LFUCache(int capacity) {
cap = capacity;
vals = new HashMap<>();
counts = new HashMap<>();
lists = new HashMap<>();
lists.put(1, new LinkedHashSet<>());
}
public int get(int key) {
if (!vals.containsKey(key))
return -1;
// Get the count from counts map
int count = counts.get(key);
// increase the counter
counts.put(key, count + 1);
// remove the element from the counter to linkedhashset
lists.get(count).remove(key);
// when current min does not have any data, next one would be the min
if (count == min && lists.get(count).size() == 0)
min++;
if (!lists.containsKey(count + 1))
lists.put(count + 1, new LinkedHashSet<>());
lists.get(count + 1).add(key);
return vals.get(key);
}
public void set(int key, int value) {
if (cap <= 0)
return;
// If key does exist, we are returning from here
if (vals.containsKey(key)) {
vals.put(key, value);
get(key);
return;
}
if (vals.size() >= cap) {
int evit = lists.get(min).iterator().next();
lists.get(min).remove(evit);
vals.remove(evit);
counts.remove(evit);
}
// If the key is new, insert the value and current min should be 1 of course
vals.put(key, value);
counts.put(key, 1);
min = 1;
lists.get(1).add(key);
}
}
Bizongo:
rate limiter system design
https://www.youtube.com/watch?v=i-hWLw5hsHo
vimeo:
Find next greater number with same set of digits
Input => n = “218765” Output => “251678”
2 identical wires They take an hour to burn 1 - 0.5 + 0.5
Measure 45 mins with just these wires and matches Burn from both ends wire 1 => 30 mins Burn wire 2 burning => burn another end of wire 2 => 15 mins
Reverse a linked list
Cargil:
- write a sql query to get 3rd largest salary
- get the first occurrence of repeating character using streams
https://javahungry.blogspot.com/2020/05/java-8-coding-and-programming-interview-questions.html
- what happens when spring application starts
- what happens in bean container
- what are the new features of java8
- what is diff between pemGen and metaspace
- why cassandra is used
- write a code to convert string to integer
- what is dependency injection and how spring manage the same