Sde1
100+ Sde1 Interview Questions and Answers
Q1. DSA and Language Questions: 1. Difference between Arrays and ArrayList in Java. 2. Queue Implementation using Linked List. 3. BST- How would you fill a BST with a sorted array. 4. Random pointer linked-list clo...
read moreA list of technical questions related to data structures and algorithms in Java.
Arrays are fixed in size while ArrayLists can dynamically grow and shrink.
Queue can be implemented using a linked list by adding elements to the end and removing from the front.
To fill a BST with a sorted array, we can recursively divide the array in half and add the middle element as the root.
Random pointer linked-list clone can be done by creating a new node for each node in the original list an...read more
Q2. 1. What is a doubly-linked list? And real-world applications.
A doubly-linked list is a data structure where each node contains a reference to both the previous and next nodes.
Allows traversal in both directions
Used in implementing LRU cache
Used in browser history
Used in undo-redo functionality
Sde1 Interview Questions and Answers for Freshers
Q3. pid ={3,5,0,1} ppid ={5,4,2,2} process id(pid) ppid=parent process id let us say the process that we killed is 2 now we have to print 2,0,1 as 0,1 are child of 2 and suppose that if we have children for this 0,...
read moreGiven a list of process IDs and their corresponding parent process IDs, print the IDs of all processes that are children of a specific process ID, and recursively kill all their children.
Iterate through the list of process IDs and parent process IDs
Check if the current process ID is the one to be killed
If yes, recursively find and print all its children
If a child has further children, recursively kill them as well
Q4. Given one point and circle how will you find if it's inside circle or outside circle
Check if a point is inside or outside a circle
Calculate the distance between the center of the circle and the given point using the distance formula
If the distance is less than the radius of the circle, the point is inside the circle
If the distance is equal to the radius of the circle, the point is on the circle
If the distance is greater than the radius of the circle, the point is outside the circle
Q5. N queen problem with problem statement and dry running of code with 4 queens and then writing the code
N queen problem is to place N queens on an NxN chessboard without any two queens threatening each other.
The problem can be solved using backtracking algorithm
Start with placing a queen in the first row and move to the next row
If no safe position is found, backtrack to the previous row and try a different position
Repeat until all queens are placed or no safe position is found
Code can be written in any programming language
Example: https://www.geeksforgeeks.org/n-queen-problem-b...read more
Q6. Sub set problem(Check if there exists any sub array with given sum in the array ) . But the thing here is that we have to do it with space complexity of only O( 1 K ) . K is the sum given .
Check if there exists any sub array with given sum in the array with O(1K) space complexity.
Use two pointers to traverse the array and maintain a current sum.
If the current sum is greater than the given sum, move the left pointer.
If the current sum is less than the given sum, move the right pointer.
If the current sum is equal to the given sum, return true.
Share interview questions and help millions of jobseekers 🌟
Q7. During Binary search, what if negative elements were there in an Array as well how would you search a specific element and time complexity for the same.
Negative elements in array won't affect binary search. Time complexity remains O(log n).
Binary search works by dividing the array into two halves and comparing the middle element with the target element.
If the middle element is greater than the target, search in the left half, else search in the right half.
Negative elements won't affect this process as long as the array is sorted.
Time complexity remains O(log n) as the search space is halved in each iteration.
Q8. What is the difference between references and pointers
References and pointers are both used to access memory locations, but references cannot be null and cannot be reassigned.
Pointers can be null and can be reassigned to point to different memory locations.
References are automatically dereferenced, while pointers need to be explicitly dereferenced.
Pointers can perform arithmetic operations, while references cannot.
Example: int x = 5; int *ptr = &x; int &ref = x;
Example: int *ptr = nullptr; int &ref = x; // not allowed
Sde1 Jobs
Q9. What happens when we type an URL
When we type an URL, the browser sends a request to the server hosting the website and retrieves the corresponding webpage.
The browser parses the URL to extract the protocol, domain, and path.
It resolves the domain name to an IP address using DNS.
The browser establishes a TCP connection with the server.
It sends an HTTP request to the server.
The server processes the request and sends back an HTTP response.
The browser receives the response and renders the webpage.
Q10. what is difference between reference variable and actual reference
A reference variable is a variable that holds the memory address of an object, while an actual reference is the object itself.
A reference variable is declared with a specific type and can only refer to objects of that type.
An actual reference is the object itself, which can be accessed and manipulated using the reference variable.
Changing the value of a reference variable does not affect the original object, but changing the value of an actual reference does.
Reference variabl...read more
Q11. 7. What is the difference between In-memory DB and MySQL?
In-memory DB stores data in RAM for faster access while MySQL stores data on disk.
In-memory DB is faster than MySQL as it eliminates disk I/O operations.
In-memory DB is suitable for real-time applications that require low latency.
MySQL is suitable for applications that require data persistence and durability.
In-memory DB may not be suitable for large datasets as it requires a lot of RAM.
MySQL supports complex queries and transactions while In-memory DB may not.
Examples of In-...read more
Q12. Two uniform wires totally burnt in a total of 30 minutes. How will you measure 45 minutes?
Burn one wire at both ends and the other wire at one end. When the first wire burns out, light the other end of the second wire.
Burn one wire at both ends and the other wire at one end
When the first wire burns out, light the other end of the second wire
The second wire will burn for 15 minutes, totaling 45 minutes
Q13. how compiler differentiate between different function with same signature. Name mangling
Name mangling is used by compilers to differentiate between different functions with the same signature.
Name mangling is a process of encoding/decoding function names to include additional information such as parameter types and namespaces.
This allows the compiler to differentiate between functions with the same name and signature.
For example, in C++, two functions with the same name and signature but in different namespaces will have different mangled names.
Name mangling is ...read more
Q14. What's Copy Constructor and how and why it is used
Copy constructor creates a new object by copying the values of an existing object.
Copy constructor is used to create a new object with the same values as an existing object.
It is invoked when a new object is initialized with an existing object.
It is used to avoid shallow copy and ensure deep copy of objects.
Example: MyClass obj1; MyClass obj2 = obj1; //copy constructor called to create obj2
Q15. 7. Print internal nodes of a binary tree (internal nodes means except nodes present in the left and right view)
Print internal nodes of a binary tree (excluding left and right view nodes)
Traverse the tree in post-order and check if the node has both left and right children
If yes, then it is an internal node and print it
If no, then continue traversing the tree
Example: For the tree 1-2-4-5-3, the internal nodes are 2 and 4
Q16. What is indexing in DBMS How do we maintain it
Indexing in DBMS is a technique to improve query performance by creating a data structure that allows faster data retrieval.
Indexing is used to speed up data retrieval operations in a database.
It involves creating a separate data structure that maps the values of a specific column to their corresponding records.
This data structure is called an index.
Indexes are typically created on columns that are frequently used in search conditions or join operations.
Maintaining an index i...read more
Q17. BST- How will you fill a BST with a sorted Array?
To fill a BST with a sorted array, we can use a recursive approach.
Find the middle element of the array and make it the root of the BST
Recursively construct the left subtree using the left half of the array
Recursively construct the right subtree using the right half of the array
Q18. What's smart pointers Which IDE you use Have you used GDB?
Smart pointers are objects that manage the memory of dynamically allocated objects, preventing memory leaks and dangling pointers.
Smart pointers are a type of RAII (Resource Acquisition Is Initialization) technique.
They automatically delete the object they point to when it is no longer needed.
Examples of smart pointers include unique_ptr, shared_ptr, and weak_ptr in C++.
They are used to prevent memory leaks and dangling pointers.
I use Visual Studio Code as my IDE.
Yes, I have ...read more
Q19. What's difference between ordered map and unordered map
Ordered map maintains the order of insertion while unordered map does not.
Ordered map is implemented using a balanced binary search tree while unordered map is implemented using a hash table.
Ordered map is useful when we need to maintain the order of insertion while unordered map is useful when we need faster access to elements.
Example of ordered map: std::map in C++, Example of unordered map: std::unordered_map in C++
Q20. How does virtual function works. What's Vptr and Vtable. Why virtual function is needed
Virtual functions allow dynamic binding of functions at runtime. Vptr and Vtable are used to implement this feature.
Virtual functions are declared in base class and can be overridden in derived classes.
Vptr is a pointer to Vtable which contains addresses of virtual functions.
Virtual function is needed to achieve polymorphism and to allow derived classes to have their own implementation of a function.
Virtual functions are resolved at runtime based on the object type rather tha...read more
Q21. find the height of the tree when the leaf nodes are connected with each other
The height of the tree can be found by counting the number of edges from the root to the farthest leaf node.
Count the number of edges from the root to the farthest leaf node
This will give the height of the tree
Example: If the farthest leaf node is 4 edges away from the root, the height of the tree is 4
Q22. How does Binary search be done in a rotated array?
Binary search in a rotated array can be done by finding the pivot point and then applying binary search on the two subarrays.
Find the pivot point by comparing mid element with the first and last elements of the array
Apply binary search on the two subarrays formed by the pivot point
Repeat until the element is found or the subarray is empty
Time complexity is O(log n)
Example: [4,5,6,7,0,1,2], target=0. Pivot point is 3. Binary search on [4,5,6,7] and [0,1,2]
Q23. What is caching? explain in detail.
Caching is the process of storing frequently accessed data in a temporary storage to improve performance.
Caching improves performance by reducing the need to fetch data from the original source.
It involves storing data in a temporary storage, such as memory or disk, closer to the user or application.
Caching can be done at various levels, including browser caching, server-side caching, and database caching.
Examples of caching include caching web pages, caching database query r...read more
Q24. AVL trees with examples and their balancing
AVL trees are self-balancing binary search trees. They maintain a balance factor to ensure height balance.
AVL trees are named after their inventors, Adelson-Velsky and Landis.
They are height-balanced, meaning the difference in height between left and right subtrees is at most 1.
Insertion and deletion operations may cause imbalance, which is corrected by rotations.
AVL trees have a worst-case time complexity of O(log n) for search, insertion, and deletion.
Example: Inserting 5, ...read more
Q25. Print Fibonacci numbers until the nth term using only recursion (no loop allowed)
Printing Fibonacci numbers using recursion only
Define a recursive function that takes two arguments, n and a list to store the Fibonacci sequence
Base case: if n is 0 or 1, return the list
Recursive case: append the sum of the last two elements in the list to the list and call the function with n-1
Call the function with n and an empty list to start the sequence
Print the list of Fibonacci numbers
Q26. Write C++ program to find absolute difference between sum of diagonal elements
C++ program to find absolute difference between sum of diagonal elements
Create a 2D array
Calculate sum of diagonal elements
Calculate absolute difference
Print the result
Q27. Puzzles: 1. Plane and Fuel Puzzle 2. Two uniform wires completely burned in a total of 30 mins. How will you measure 45 mins
Answering two puzzles - Plane and Fuel, and Two Wires Burned
For the Plane and Fuel puzzle, calculate the amount of fuel needed for half the journey and then double it
For the Two Wires Burned puzzle, light one wire at both ends and the other wire at one end only after the first wire has burned out halfway
Both puzzles require creative thinking and problem-solving skills
Q28. 2. Advantage of doubly linked list over singly LL?
Doubly linked list allows traversal in both directions, while singly linked list only allows traversal in one direction.
Doubly linked list allows for efficient deletion of nodes compared to singly linked list.
Doubly linked list can be traversed in both forward and backward directions.
Doubly linked list can be used to implement a stack or queue.
Singly linked list requires less memory than doubly linked list.
Doubly linked list is more complex to implement than singly linked lis...read more
Q29. Implementation of LRU (WIth Production level code)
Implementation of LRU cache using a doubly linked list and a hash map.
LRU (Least Recently Used) cache is a data structure that stores a fixed number of items and evicts the least recently used item when the cache is full.
To implement LRU cache, we can use a doubly linked list to maintain the order of items based on their usage frequency.
We can also use a hash map to store the key-value pairs for quick access and retrieval.
When a new item is accessed, it is moved to the front ...read more
Q30. What is the fastest sorting algorithm?
The fastest sorting algorithm is QuickSort.
QuickSort has an average time complexity of O(n log n).
It is a divide and conquer algorithm that recursively partitions the array.
It is widely used in practice and has many variations such as randomized QuickSort.
Other fast sorting algorithms include MergeSort and HeapSort.
Q31. 4. Explain the internal working of the above question.
The question is unclear and requires clarification.
The question is not specific about what 'above question' it is referring to.
The term 'internal working' is also vague and needs to be defined.
Without more information, it is impossible to provide a meaningful answer.
Q32. Write a react js parent and child components and show how passing props work?
Example of React parent and child components with props
Create a parent component with state and pass it as props to child component
Access the props in child component using 'props' keyword
Update the parent state from child component using a callback function passed as prop
Example: Parent component -
Example: Child component -
Q33. 1.What is Rdbms? 2.What is polymorphism and inheritance? 3.What is trigger? 4.Difference between span tag and div tag?
Answers to technical questions related to RDBMS, polymorphism, inheritance, triggers, and HTML tags.
RDBMS stands for Relational Database Management System and is used to manage relational databases.
Polymorphism is the ability of an object to take on many forms, while inheritance is the process of creating new classes from existing ones.
A trigger is a set of instructions that are automatically executed in response to a specific event or change in a database.
The span tag is use...read more
Q34. Write a factorial program and explain it and define class syantax
Factorial program using class syntax explained with examples.
Factorial is the product of all positive integers up to a given number.
Class syntax is used to define a blueprint for creating objects.
Example: class Factorial { def fact(n): return 1 if n == 0 else n * fact(n-1) }
Example: f = Factorial(); print(f.fact(5)) # Output: 120
Q35. what is NP hardness .
NP hardness refers to the difficulty of solving a problem in non-deterministic polynomial time.
NP-hard problems are some of the most difficult problems in computer science.
They cannot be solved in polynomial time by any known algorithm.
Examples include the traveling salesman problem and the knapsack problem.
Q36. Given two words determine the similarity between them
The question asks to determine the similarity between two words.
Use a similarity metric like Levenshtein distance or cosine similarity
Normalize the words by converting them to lowercase and removing punctuation
Consider using a pre-trained word embedding model for semantic similarity
Implement a function that calculates the similarity score between two words
Q37. Difference between heap and stack and how memory clean up is done?
Heap and stack are two different memory regions in a computer's memory. Heap is used for dynamic memory allocation, while stack is used for static memory allocation.
Heap is used for dynamic memory allocation, while stack is used for static memory allocation.
Heap memory is allocated at runtime and can be accessed randomly, while stack memory is allocated at compile time and accessed in a last-in-first-out manner.
Memory clean up in heap is done manually by the programmer using ...read more
Q38. 3. Applications of Graph Data Structure
Graph data structure is used in various applications such as social networks, routing algorithms, and recommendation systems.
Social networks use graphs to represent users and their connections.
Routing algorithms use graphs to find the shortest path between two points.
Recommendation systems use graphs to analyze user behavior and suggest relevant items.
Graphs are also used in computer networks, image processing, and machine learning.
Examples include Dijkstra's algorithm, PageR...read more
Q39. B trees , B+ trees with examples
B trees and B+ trees are data structures used for efficient storage and retrieval of data in databases.
B trees are balanced trees with a variable number of child nodes per parent node. They are commonly used in databases to store large amounts of data.
B+ trees are a variant of B trees where all data is stored in the leaf nodes, and the internal nodes only contain keys. They are commonly used in databases for indexing.
B+ trees are more efficient than B trees for range queries ...read more
Q40. Find the product of all elements in the array except that element in linear time
Find the product of all elements in the array except that element in linear time.
Initialize a result array with the same length as the input array
Calculate the product of all elements to the left of each element and store it in the result array
Calculate the product of all elements to the right of each element and multiply it with the corresponding element in the result array
Return the result array
Q41. DSA qn: Given a string find a first repeating character. Eg: String is "abcbca" , ans > "a"
Given a string, find the first repeating character.
Use a hash table to keep track of characters and their frequency.
Iterate through the string and check if the character is already in the hash table.
Return the first character with a frequency greater than 1.
Q42. SQL qn: standard qn, find the 2nd highest salary Find the nth highest salary from table employee
SQL query to find nth highest salary from employee table
Use ORDER BY and LIMIT clauses
For 2nd highest salary use LIMIT 1,1
For nth highest salary use LIMIT n-1,1
Q43. Difference between Arrays & ArrayLists in Java?
Arrays are fixed in size while ArrayLists can dynamically grow or shrink.
Arrays are of fixed size while ArrayLists can be resized dynamically.
Arrays can hold primitive data types while ArrayLists can only hold objects.
Arrays are faster than ArrayLists for accessing elements.
ArrayLists have built-in methods for adding, removing, and sorting elements.
Example: int[] arr = new int[5]; ArrayList
list = new ArrayList<>();
Q44. what's' polymorphism and how it works
Polymorphism is the ability of an object to take on many forms. It allows objects of different classes to be treated as if they were the same type.
Polymorphism is achieved through method overriding and method overloading.
Method overriding is when a subclass provides a specific implementation of a method that is already provided by its parent class.
Method overloading is when a class has two or more methods with the same name but different parameters.
Polymorphism allows for mor...read more
Q45. Round 3: How to compute requests per second in an application.
To compute requests per second in an application
Identify the number of requests received by the application in a given time frame
Divide the number of requests by the time frame to get requests per second
Use load testing tools like JMeter to simulate traffic and measure requests per second
Optimize application performance to handle high traffic and increase requests per second
Q46. Find the number of buildings to the left and right that can be viewed from the top of each building in a sequence of buildings.
Given a sequence of buildings, find the number of buildings visible to the left and right from the top of each building.
Traverse the sequence of buildings from left to right and maintain a stack of visible buildings.
For each building, pop all the buildings from the stack that are shorter than the current building and count them as visible to the left.
Push the current building onto the stack and count the number of buildings in the stack as visible to the right.
Repeat the proc...read more
Q47. Explain currying in JS? sum(1)(2)(); sum(2)(4)(); All these should return sum of numbers
Currying is a technique of transforming a function that takes multiple arguments into a sequence of functions that each take a single argument.
Currying is achieved by returning a function that takes the next argument until all arguments are received.
In JavaScript, currying is often used for partial application of functions.
The sum function in the example takes one argument and returns a function that takes the next argument until all arguments are received.
The final function ...read more
Q48. What are different types of streams
Streams are a sequence of data elements made available over time. There are different types of streams.
Byte Streams
Character Streams
Buffered Streams
Data Streams
Object Streams
Print Streams
File Streams
Network Streams
Q49. What's shallow and deep copy
Shallow copy creates a new object with the same reference as the original, while deep copy creates a new object with a new reference.
Shallow copy only copies the reference to the original object, so changes made to the copy will affect the original object.
Deep copy creates a new object with a new reference, so changes made to the copy will not affect the original object.
In Python, shallow copy can be made using the copy() method, while deep copy can be made using the deepcopy...read more
Q50. OOPS: 1. Polymorphism with example 2. Overloading vs overriding
Polymorphism is the ability of an object to take on many forms. Overloading is having multiple methods with the same name but different parameters. Overriding is having a method in a subclass with the same name and parameters as a method in the superclass.
Polymorphism allows objects to be treated as if they are of different types. For example, a parent class reference can be used to refer to a child class object.
Overloading is used to provide different implementations of a me...read more
Top Interview Questions for Sde1 Related Skills
Interview experiences of popular companies
Calculate your in-hand salary
Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary
Reviews
Interviews
Salaries
Users/Month