Some of the Interview Questions
-
Is it possible for an abstract class to extend another abstract class?
-
how many interface can one interface extend?
-
Is constructor present in abstract class
-
is it possible to create an object for an abstract class?
-
write a sql query to find the users who are not logged in more than 7 days. consider two tables
Users:
userid
firstaname
lastname
emailid
password hash
passowrduserloginHistory:
userid
logintimestamp -
Write a function boolean sumOf2(int[] arr, int sum) which returns true if there is a pair of numbers in arr that add up to sum.
-
find number of rotation performed in roated sorted array.
-
int[] arr = new int[]{12, 34, 56, 789, 567, 345, 234 ,123}; - Array of integers ordered as increasing and starts decreasing. Find the maximum element.
-
String str = #A@FT%S#GHU; Reverse the string and maintain the index of the special characters.
-
Difference between abstract classes and interfaces.
-
Advantages of Spring Boot over Vanilla Spring.
-
How Spring Beans work internally?
-
Explain about Apache Solr.
-
Explain about Apache Kafka.
-
How google search works, How the data was stored and which data structures was used.
-
Difference between REST and Kafka, Which one do we have to prefer on what scenario?
-
Explain about GC? which algorithm used in it.
-
what is docker? how you deploy your application in the machine.
-
what is kubernetes? how it differs from docker?
-
Difference between RabbitMQ and Kafka
-
What is API Gateway?
-
What is Service Registry and Service Discovery in Microservices.
-
Explain circuit breaker
-
How two microservices communicate to each other?
-
SQL Query to get list of credited and debited details having amount greater than 500 group by userid incoming outgoing
- user id - user id
- amount - amount
- date - date
total incoming total outcoming for each day amount > 500
- How much volume of data you have migrated in your project?
- Server capacity and memory allocation for your servers in production for the proposed volume of data.
- How sharding can be done for mongodb?
- Design a system to input a large file containing book tiles and response query for word search. why you use solr and mongo? what's the purpose of mongo over here>.
- Replace a request of stock results for company to a request takes multipe stock request for different companies and responds the results without affecting the time. it should response results as quick as the previous ones.
- How you will process a large set of files. For example take a log system having terra bytes of data in singe file process the file, mask the desired data in the log text and write back to a file.
- how will you merge the chunks without data overlapping.
- Have you trained any junior resources before.
- which spring boot version are you using?
- pros and cons of using microservices agains monolith. Difference, advantages and disadvantages of Monolith and microservice architectures.
- Time complexity to get an element in array and list.
- Difference between MySQL and NoSQL - Explain CAP Theorem.
- Explain about JVM.
- Explain Time and Space Complexity.
- Explain CI/CD
- Explain your TDD Process.
- Horizontal vs Vertical Scaling.
- Explain SOLID Principles.
- Difference between Process and Threads.
-
Find the first repeating character in a String. Order of the character to be considered.
Ex: ABCA - A
Glovol - l``` public String findFirstRepeatingCharacter(String s) { LinkedHashMap<Integer, Integer> charOccuranceMap = new LinkedHashMap(); char[] charArr = s.toCharArray(); for(int idx = 0; idx < charArr.length; idx++) { // System.out.println("" + (char)charArr[idx]); // Character c = (char)charArr[idx]; int occuranceCount = 1; Integer charVal = (int)charArr[idx]; if(charOccuranceMap.containsKey(charVal)) { occuranceCount = charOccuranceMap.get(charVal); occuranceCount++; } charOccuranceMap.put(charVal, occuranceCount); } for(Map.Entry<Integer, Integer> entry : charOccuranceMap.entrySet()) { //int cInt = entry.getKey(); //System.out.println( ((char)cInt) + " " + entry.getValue()) ; if(entry.getValue() > 1) { int cInt = entry.getKey(); return "" + (char)cInt; } } return ""; /* int[] HASH = new int[256]; char[] charArr = s.toCharArray(); int idx = 0; while(idx < charArr.length) { HASH[charArr[idx]]++; if(HASH[charArr[idx]] > 1) return "" + charArr[idx]; idx++; } return ""; */ } ``` -
Paranthesis Match.
()[]{} - true
([]) - falsepublic boolean isParanthesisBalanced(String s) { char[] charArr = s.toCharArray(); Stack<Character> charStack = new Stack(); List<Character> openBracesList = Arrays.asList(new Character[]{'(', '[', '{'}); List<Character> closeBracesList = Arrays.asList(new Character[]{')', ']', '}'}); int indexOfChar = -1; for(int i = 0; i < charArr.length; i++) { if(openBracesList.contains(charArr[i])) { indexOfChar = openBracesList.indexOf(charArr[i]); charStack.push(charArr[i]); } if(closeBracesList.contains(charArr[i])) { if(closeBracesList.indexOf(charArr[i]) != indexOfChar) return false; charStack.pop(); } } System.out.println("--- isBalanced: " + charStack.isEmpty()); return charStack.isEmpty(); }
- Difference between an Abstract class and Interface.
- Can We have main() method in Abstract Class?
- How to remove duplicates in ArrayList?
- Which is the preferred datatype for storign password?
- Difference between HashMap and HashTable
- Do you konw about Collections.synchronized() ?
- Difference between Collections.synchronized(HashMap) and ConcurrentHashMap
- What is the difference between an ordered and a sorted collection?
- Consider We have a map having integer key and string value. Can you sort the Map withe ascending order of keys.
- Can you explain overriding and overloading?
- Is it possible to declare a variable final and not initializing values. ex: final int a;
- StringBuffer vs StringBuilder
- What is a memory leak?
- Consider a system is having out of memory exception. How will you debug?
- Consider there is a REST API Service, which you have to call from your java application. the REST Service will be down if more than 3 requests accessed at a time. Add rate limit in the java application.
- First unique character in a String ex: "ABCAAC" ans: "B"
- Can you explain Singleton?
- Can we declare a class Static in Java?
- In java which are all stores in Stack memory and Heap memory.
- can you differentiate == with equals method.
- What is the contract between equals and hashcode method.
- Find the largest two numbers in an Integer Array
- JVM Memory Management
- String, String Buffer and String Builder - Comparision, Which is Efficient?
- When ArrayList compared to LinkedList which is best of read operation and which one for right operation?
- Explain SOLID Principles
- What is the Major advantages of Loosly Coupled System(Data Abstraction), Why We have to go with Dependency Injection.
- What is Data Abstraction.
- How to provide thread safety for a class having one variable and one method. without using Synchronization.
- Explain Kafka, Partition? Why Partition is used how the partition limit was determined?
- What is Hadoop? Explain Map-Reduce
- Difference between Error and Exception
- How to avoid Exception?
- What is High Availability?
- Explain o(LogN). Explain the search between ordered array and unordered array.
- Explain about GC. Which one you are using?
- Why you are leaving your present company?
- Are you willing to migrate?
- how to deal with the client which continuously brings new requirement and want it for yesterday, etc
- what is your goal in your life?
- Explain one problem where you outwitted yourself.
- what would be the output?
class Test {
public static void main(String...args) {
try {
badMethod();
System.out.println("A");
} catch(Exception e) {
System.out.println("B");
} finally {
System.out.println("C");
}
System.out.println("D");
}
public static void badMethod() {
}
}
- What would be the output ?
java Test -DopenDog=Roetweeler
class Test {
public static void main(String...args) {
Properties p = System.getProperties();
p.setProperty("dog", "scrunky");
String openDog = p.getPropert("openDog");
String dog = p.getProperty("dog");
dog += openDog;
System.out.println(dog);
}
}
- What is the root(apex) of exception hierarrchy in Java?
- How many return statements are allowed in python function?
- Write a python program contains functions to remove vowels in a string and consonents in a string. print seperately.
- Write default implementations for an interface in java
- What would be the output of the below function
a = 0
for b in range(0, 10, 2):
a += b + 1;
- What would be the output of the below function
def foo(a, b, c) : pass
- A multiple choice question contains key value paris. Which of the below is the correct key value combination in hashtable.
- select id, name from customer and sort the values by name ascending if two of the customer has same name then sort those by id asc.
- A merchant has 1000 kg of sugar, part of which he sells at 8% profit and the rest at 18% profit. He gains 14% on the whole. The quantity sold at 18% profit is?
- What would be the output?
int[] a = new int[]{1,2,5,2,3,7,9,1,2,6};
add elements of array to a set
add set values to a list and sort it by ascending
- REST constraints based question
- FizzBuzz in Java (Sample Program) - runtime of the program should not exceed 4ms Write a program that outputs the string representation of numbers from 1 to n.
But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
public List<String> fizzBuzz(int n) {
List<String> result = new ArrayList<>();
if(n < 1) return result;
for(int i = 1, fizz = 3, buzz = 5; i <= n; i++) {
String addVal = null;
if(i == fizz && i == buzz) {
addVal = "FizzBuzz";
fizz += 3;
buzz += 5;
} else if(i == fizz) {
addVal = "Fizz";
fizz += 3;
} else if(i == buzz) {
addVal ="Buzz";
buzz += 5;
} else
addVal = String.valueOf(i);
result.add(addVal);
}
return result;
}
- URI constraints based question. (Sample)
- Which of the following data structures can erase from its beginning or its end in O(1) time? (Sample)
- Explain Yourself
- Why are you switching job?
- Why Auto1
- REST - What is Itempotent methods?
- Explain HTTP Methods
- Which HTTP Methods are Safe? - An HTTP method is safe if it doesn't alter the state of the server. In other words, a method is safe if it leads to a read-only operation. Several common HTTP methods are safe: GET , HEAD , or OPTIONS . All safe methods are also idempotent,but not all idempotent methods are safe
- Spring - Spring bean scopes
- Spring - Which Spring bean scope is thread safe(Singleton not thread safe)
- Types of Autowiring - (The autowiring functionality has four modes. These are ' no ', ' byName ', ' byType ' and ' constructor ')
- Transaction propagation in spring -
- Java - contract between equals and hashcode method
- Functional Interfaces - and its types
- List which collections from java you've used
- Super class for unchecked exception and for checked exception?
- How long you need for relocation
- Salary Expectation
- Air Plane Seating alogrithm : https://github.com/karthij15/squareshift
- Drawbacks of Monolith
- Explain a scenario which you come across related to data incosistency
- How will you handle inventory out of stock scenario
- How you will review a code? Review your submitted code.
- Explain about yourself
- Deep questions about previous projects
- Few of My GitHub programs discussed LRUCache, RotateArray
- Rotate characters in a string not using the above RotateArray approach (used string concat and substring)
- Do left rotate and again right rotate the characters(cancel the repetetive approaches). Refactor the code.
-
3 different array having elements in different sequential orders. combine in single array in ascending order S1 [1, 4, 9] S2 [2, 5, 7, 8] S3 [3, 6]
Result [1, 2, 3, 4, 5, 6, 7, 8, 9]
-
Design a TinyURL System
- Why Kafka Over ActiveMQ
- What's your typical Day!
- How are you managing your team
- Given a sorted array of integers, find the starting and ending position of a given target value. If the target is not found in the array, return [-1, -1]. Example: Given [5, 7, 7, 8, 8, 10] and target value 8, return [3, 4].
- A [ 8, 23, 22, 16, 22, 7, 7, 27, 35, 27, 32, 20, 5, 1, 35, 28, 20, 6, 16, 26, 48, 34 ] Return the first lowest number lower than the current index The expected returned value : O: -1 8 8 8 16 -1 -1 7 27 7 27 7 -1 -1 1 1 1 1 6 16 26 26
The longest palindromic substring of the the given input. Ex: hackerrekcahbahh Ans: hackerrekcah
You just got a new job where you have to work exactly as many hours as you are told each week, working no more than a daily maximum number of hours per day. Some of the days, they tell you how many hours you will work. You get to choose the remainder of your schedule, within the limits.
A completed schedule consists of exactly 7 digits in the range 0 to 8 representing each day's hours to be worked. You will get a pattern string similar to the schedule, but with some of the digits replaced by a question mark, ?, (ascii 63 decimal). Given a maximum number of hours you can work in a day, replace the question marks with digits so that the sum of the scheduled hours is exactly the hours you must work in a week. Return a string array with all possible schedules you can create, ordered lexicographically.
For example, your partial schedule, pattern = 08??840, your required hours, work_hours = 24, and you can only work, at most, day_hours = 4 hours per day during the two days in question. You have two days on which you must work 24 - 20 = 4 more hours for the week. All of your possible schedules are listed below:
0804840 0813840 0822840 0831840 0840840 Function Description Complete the function findSchedules in the editor below. The function must return an array of strings that represents all possible valid schedules. The strings must be ordered lexicographically.
findSchedules has the following parameter(s):
work_hours: an integer that represents the hours you must work in the week
day_hours: an integer that represents the maximum hours you may work in a day
pattern: a string that represents the partially completed schedule
Constraints 1 ≤ work_hours ≤ 56 1 ≤ day_hours ≤ 8 | pattern | = 7 Each character of pattern ∈ {0, 1,...,8} There is at least one correct schedule. Input Format For Custom Testing The first line contains an integer, work_hours The second line contains an integer, day_hours The third line contains a string, pattern
Sample Case 0 Sample Input 0
56 8 ???8??? Sample Output 0
8888888 Explanation 0
work_hours = 56 day_hours = 8 pattern = ???8??? There is only one way to work 56 hours in 7 days of 8 hours.
Sample Case 1
Sample Input 1
3 2 ??2??00 Sample Output 1
0020100 0021000 0120000 1020000 Explanation 1
work_hours = 3 day_hours = 2 pattern = ??2??00 You only need to schedule 1 more hour for the week, and it can be on any one of the days in question.
Multiple processors running with different process, find processors, required
Given there are multiple processors available to execute the given program. Each program are split into multi process in such a way each process has some start time and end time based on the time it takes to run. Different process are feed to processors to execute, goal is to minimize the time taken and ensure the processors are completed with least time. Find out the minimum no of processors required to execute the given processes. No of process and its start time to execute the process is been provided. Use the compute method to find the minimum number of processors required to execute them..
Example
with the given starting time of the process, ending time of the processes as below need to identify the minimum number of processors required.
//as far remembered two array of times will be the input. expected output is an Integer String[] start_time = new String["12.09.20:09:39", "09.09.20:09:39", "01.08.20:09:39"] String[] end_time = new String["03.01.20:09:39", "02.09.20:09:39", "01.08.20:09:39"]
- What would be the output?
int a = 260;
byte b = (byte)a;
System.out.println(b);
- What would be the output ?
int[] a = new int[] {1, 2, 3};
int[] o = Arrays.copyOf(a, 5);
int[] c = Arrays.copyOfRange(o, 0, 4); //line 3
for(int i : c) {
System.out.println(i);
}
Compile Error: line 3 returns int not int[].
- what would be the output?
int temp = 40;
if(temp == 30 && temp/0 == 4) {
System.out.println(1);
} else {
System.out.println(2);
}
- What would be the output?
for(int i = 0; i > 5; ) {
System.out.println("Hell0" + i);
}
System.out.println("Completed!");
- what will be the output?
String temp = "10.87";
int a = Integer.parseInt(temp);
System.out.println(a);
Will throw a RunTime Error
- What would be the output?
String s1 = "java";
String s2 = s1.intern();
String s3 = "java";
String s4 = new String("java");
StringBuffer sb = new StringBuffer("java");
System.out.println((s1 == s2) + (s2==s3) + (s3 == s4) + (s1 == s4));
- What would be the output?
int[] a = new int[10];
byte[] b = new byte[10];
char[] c = new char[10];
double[] d = new double[10];
System.out.println(a[0] + "" + b[0] + "" + c[0] + "" + d[0]);
- What would be the output?
System.out.println(1 +
2==+
3+
+
+5+
++6 +
--7);
- What would be the output?
String a = "abc";
String b = "abc";
System.out.println(a == b);
- what would be the output?
int b = 96;
System.out.println(b >>4);
System.out.println(b >>>4);
- which of the below statement is wrong?
1.int a[][] = {{1,2},{12,2,22}};
2.int b[] = new int[2]{1,2};
3.int i[][] = {{1,2},{12,2,22}}, b = 2;
- what would be the output?
public static int temp1 = 1;
private static int temp2 = 2;
private int temp4 = 4;
public static class inner {
private static int getSumOf2() {
return (temp1 + temp2);
}
private static int getSumOf4() {
return (temp1 + temp4);
}
}
- Which line compiler will throw the error?
public static int temp1 = 1;
public static int temp2 = 2;
public int temp3 = 3;
private int temp4 = 4;
public class InnerClass {
private static int getSum()
{
return temp1 + temp2;
}
}
- What would be the output?
class Test {
public static void main(String[] args) {
int x = 30;
System.out.println(x);
}
static {
int x = 10;
System.out.println(x);
}
}
- Which of the following is correct recurrence for worst case of Binary Search? (A) T(n) = 2T(n/2) + O(1) and T(1) = T(0) = O(1) (B) T(n) = T(n-1) + O(1) and T(1) = T(0) = O(1) (C) T(n) = T(n/2) + O(1) and T(1) = T(0) = O(1) (D) T(n) = T(n-2) + O(1) and T(1) = T(0) = O(1)
Ans: C
- Given a sorted array of integers, what can be the minimum worst case time complexity to find ceiling of a number x in given array? Ceiling of an element x is the smallest element present in array which is greater than or equal to x. Ceiling is not present if x is greater than the maximum element present in array. For example, if the given array is {12, 67, 90, 100, 300, 399} and x = 95, then output should be 100. (A) O(LogLogn) (B) O(n) (C) O(Logn) (D) O(Logn * Logn)
Answer: C
- What would be the output?
public static void main(String[] args) {
System.out.println("Hello");
5<6?6:5;
}
- What is the name of this tree?
/ \
15 30
/ \ / \
40 50 100 40
/ \ /
8 7 9
a) Binary Tree b) Binary Search Tree c) Complete Tree d) Full Tree
-
Level order Tree Traversal also known as _____________________
-
What is Widening Type convertion in Java?
-
Fill the blanks A Java thread dump is a way of finding out what every thread in the ___________ is doing at a particular point in time. This is especially useful if your Java application sometimes seems to hang when running under load, as an analysis of the dump will show where the ___________ are stuck.
-
List of statements based question about ExecutorService in java, from which we have to identify which one is incorrect amoung them
-
List of statements based question about JVM Heap, PermGen, Xms, Xmx and Xmn in java, from which we have to identify which one is incorrect amoung them
-
List of statements based question about Packages in java, from which we have to identify which one is incorrect amoung them
-
List of statements based question about Generics in java, from which we have to identify which one is incorrect amoung them (generics are run time type correctness(X), A lower bounded wildcard is expressed using the wildcard character ('? '), following by the super keyword, (Y))
-
Which of the following is not true for garbage collection?
-
What would be the output?
import static java.lang.System.*;
public static void main(String[] args) {
out.println("test");
}
- Select ONE or MORE Rules manadatory for maitaining URL Standards
- What would be the output?
class NewThread extends Thread {
public void run() {
for(int i = 0; i < 500; i ++) {
System.out.println("i" + i);
}
}
}
class Test {
public static void main(String...args) {
NewThread n = new NewThread();
n.setDaemon(true);
n.start();
System.out.println("Completed");
}
}
- Difference between Controller and Rest Controller
- Difference between Monolith and Microservice
- Explain some new features of Java 8
- Explain advantages of Microservices
- what is blue-green deplooyment
- What is smart end-points and dumb pipes
- Can you work as Individual Contributor or Leading a Team?
- As a part of team lead, what are the qualities you expect to have?
- What will be the one word, if we ask about you to your manager.
- Why SpringBoot? advantages over Spring
- Spring Bean lifecycle?
- Design Pattern/Architectural pattern behind API-Gateway?
- Merge two arrays without duplicates int[] a = new int[]{1, 2, 5}; int[] b = new int[]{3, 4, 6, 2};
output = {1,2,5,3,4,6}
- Print all permutaions of a String input a = "abc"
abc acb bca cab cba bac
- PreOrder traversal of a Binary Tree without recursion
- print productname from product having same cost Note: SQL queries (a table "product" with columns cost, category, and productname)
- print category from product having more than 3 items Note: SQL queries (a table "product" with columns cost, category, and productname)
- What are all the architectural patterns used in microservice?
- Difference between Monolith and Microservice?
- Microservice A <-> Microservice B (if B is down how A will respond)
- Microservice A <-> Microservice B (if A is 10000 req per sec and B is 5000 req per sec autoscale limit also reached) => kind of rate limiter
- Why Solr over Elastic search
- Design a HashMap? Which data type preferrable for the backing array?
- Like Immutable String class, create a class
- What is service discovery
- Which docker hub/host you are using? 10.Queue vs Blocking Queue
- TCP vs UDP Protocol difference
- HTTP vs GRPC
- Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example 1:
Input: strs = ["flower","flow","flight"]
Output: "fl"
Example 2:
Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.
13.Two of the nodes of a Binary Search Tree (BST) are swapped. Fix (or correct) the BST Input Tree:
10
/ \
5 8
/ \
2 20
In the above tree, nodes 20 and 8 must be swapped to fix the tree.
Following is the output tree
10
/ \
5 20
/ \
2 8