Sde1

100+ Sde1 Interview Questions and Answers

Updated 13 Dec 2024

Q51. Clone a linked list with a random pointer.

Ans.

Clone a linked list with a random pointer.

  • Create a new node for each node in the original list

  • Store the mapping of original node to new node in a hash table

  • Set the random pointer of each new node based on the mapping

  • Traverse the original list and the new list simultaneously to set the next pointers

Q52. 1. Find the contiguous sub array with max sum 2. Find the median of an array sorting is involved

Ans.

Interview question on finding max sum contiguous subarray and median of array with sorting involved.

  • For finding max sum contiguous subarray, use Kadane's algorithm which has O(n) time complexity.

  • For finding median of array, sort the array and then find the middle element or average of middle two elements.

  • If the array is too large to sort, use quickselect algorithm to find the kth smallest element in O(n) time.

Q53. U have a seesaw their are 9 people on an island one ways slightly heavier or lighter than the rest find that person in minimum no of comparisons

Ans.

Use 2 weighings to identify the different person on the seesaw among 9 people on an island.

  • Divide the 9 people into 3 groups of 3 each.

  • Weigh any 2 groups against each other.

  • If the 2 groups weigh the same, the different person is in the third group.

  • If one of the groups weighs less or more, the different person is in that group.

  • Divide the group with the different person into 3 individuals.

  • Weigh any 2 individuals against each other.

  • If they weigh the same, the different person is...read more

Q54. Given an array of 0s, 1s and 2s sort the array - expected O(n)

Ans.

Sort an array of 0s, 1s, and 2s in O(n) time complexity.

  • Use three pointers to keep track of the positions of 0s, 1s, and 2s.

  • Traverse the array and swap elements to their respective positions.

  • The first pointer should point to the first occurrence of 1, and the second pointer should point to the first occurrence of 2.

  • Example: [0, 1, 2, 0, 1, 2] -> [0, 0, 1, 1, 2, 2]

Are these interview questions helpful?

Q55. 1. Difference between RDBMS and NoSQL

Ans.

RDBMS is a structured database that uses SQL while NoSQL is a non-relational database that doesn't use SQL.

  • RDBMS stores data in tables with predefined schema while NoSQL stores data in documents, key-value pairs, or graphs.

  • RDBMS is good for complex queries and transactions while NoSQL is good for scalability and handling unstructured data.

  • Examples of RDBMS include MySQL, Oracle, and SQL Server while examples of NoSQL include MongoDB, Cassandra, and Redis.

Q56. maximum product of 2 numbers from given array

Ans.

Find the maximum product of 2 numbers from a given array.

  • Sort the array and multiply the last two elements for positive numbers.

  • If there are negative numbers, multiply the two smallest negative numbers with the largest positive number.

  • Handle edge cases like array length less than 2 or all negative numbers.

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Q57. too find all numbers whose consecutive digits differ by 1

Ans.

Find all numbers whose consecutive digits differ by 1

  • Iterate through all numbers and check if consecutive digits differ by 1

  • Start with 12 and increment by 1 until 98

  • Add the number to the result array if it satisfies the condition

Q58. connect n ropes with minimum cost(priority queue question)

Ans.

Connect n ropes with minimum cost using priority queue

  • Create a priority queue and insert all the ropes into it

  • Pop the two smallest ropes from the queue and connect them

  • Insert the new rope into the queue and repeat until only one rope remains

  • The cost of connecting two ropes is the sum of their lengths

  • Time complexity: O(nlogn)

  • Example: Ropes of lengths 4, 3, 2, and 6 can be connected with a cost of 29

Sde1 Jobs

SDE 1 - Backend 2-4 years
Dream Game Studios
3.8
Mumbai
T2-SDE 1 Backend 3-5 years
Skillmine Technology Consulting
3.7
Mumbai
SDE 1 / SDE 2 - MERN 2-6 years
M2P Solutions Pvt Ltd
3.6
Hyderabad / Secunderabad

Q59. First non repeating character in continuous character stream

Ans.

Find the first non-repeating character in a continuous character stream.

  • Use a hash table to keep track of character frequency.

  • Iterate through the stream and check if the current character has a frequency of 1.

  • If yes, return the character as the first non-repeating character.

  • If no non-repeating character is found, return null or a default value.

Q60. How vector works internally

Ans.

Vectors are dynamic arrays that allocate memory dynamically. They work by storing elements in contiguous memory locations.

  • Vectors allocate memory dynamically and store elements in contiguous memory locations

  • They can be resized dynamically as needed

  • Accessing elements is done using an index, similar to arrays

  • Inserting or deleting elements in the middle of a vector can be expensive as it requires shifting all subsequent elements

  • Vectors have a size and capacity, where size is the...read more

Q61. Fibonacci number generation using recursion.

Ans.

Fibonacci number generation using recursion

  • Define a function that takes an integer as input

  • If the input is 0 or 1, return the input

  • Else, return the sum of the function called with input-1 and input-2

  • Call the function with the desired input

Q62. Queue Implementation using Linked List?

Ans.

Queue can be implemented using a singly linked list where insertion happens at the tail and deletion at the head.

  • Create a Node class with data and next pointer

  • Create a Queue class with head and tail pointers

  • Enqueue operation: create a new node and add it to the tail of the list

  • Dequeue operation: remove the node at the head of the list and update the head pointer

  • Peek operation: return the data at the head of the list without removing it

Q63. If bully happens will you bully someone

Ans.

No, I believe in standing up against bullying and supporting those who are being bullied.

  • I do not support bullying in any form and believe in treating others with respect and kindness.

  • I would try to intervene and help the person being bullied, either by talking to the bully or seeking help from a teacher or supervisor.

  • I believe in creating a positive and inclusive environment where everyone feels safe and respected.

Q64. Leet code medium of array and dp

Ans.

Dynamic programming problem involving arrays of strings.

  • Use dynamic programming to efficiently solve problems by breaking them down into smaller subproblems.

  • Consider using a 2D array to store intermediate results for optimal substructure.

  • Examples: Longest Common Subsequence, Word Break, Minimum Path Sum.

Q65. 2. What is indexing?

Ans.

Indexing is the process of organizing data in a database or search engine to improve search efficiency.

  • Indexing creates a data structure that allows for faster retrieval of information.

  • It involves creating an index that maps the location of data in a database or search engine.

  • Indexing can be done on various types of data, such as text, numbers, and dates.

  • Examples of indexing methods include B-tree, hash, and bitmap indexing.

Q66. Show the Array Rotation

Ans.

Array rotation is the process of shifting the elements of an array to the left or right.

  • To rotate an array to the left, move the first element to the end of the array and shift the remaining elements to the left.

  • To rotate an array to the right, move the last element to the beginning of the array and shift the remaining elements to the right.

  • The number of rotations can be specified by the user.

  • Example: If the array is [1, 2, 3, 4, 5] and we want to rotate it to the left by 2 p...read more

Q67. You are given a family tree, and a node, you have to print all the nodes on the same level as it.

Ans.

Given a node in a family tree, print all nodes on the same level.

  • Traverse the tree level by level using BFS

  • Keep track of the level of each node while traversing

  • Print all nodes with the same level as the given node

  • Example: If the given node is 'John', print all his siblings and cousins

Q68. NextGreater element in array using Stack(can find on leetcode)

Ans.

Using a stack to find the next greater element in an array of strings.

  • Iterate through the array from right to left.

  • Push elements onto the stack and compare with the top element to find the next greater element.

  • Pop elements from the stack until a greater element is found or stack is empty.

Q69. Reverse each word in the string and print the sentence

Ans.

Reverse each word in a string and print the sentence

  • Split the string into words

  • Reverse each word using built-in function or loop

  • Join the reversed words to form a sentence

Q70. return true if Subarray is present whose sum is 0

Ans.

Check if there is a subarray with sum 0 in the given array of strings.

  • Iterate through the array and keep track of the running sum using a hashmap.

  • If the running sum is seen before, then there exists a subarray with sum 0.

  • Return true if a subarray with sum 0 is found, otherwise return false.

Q71. immediately invoked function to print a sequence [predict output]

Ans.

An immediately invoked function to print a sequence

  • Create a function with the sequence to be printed

  • Wrap the function in parentheses to make it immediately invoked

  • Use console.log() to print the sequence

  • Example: (function() { for(let i=1; i<=5; i++) console.log(i); })();

Q72. primitive data update vs object data update[predict output]

Ans.

Primitive data update is faster and simpler than object data update.

  • Primitive data update involves updating simple data types like integers and booleans.

  • Object data update involves updating complex data types like arrays and objects.

  • Primitive data update is faster and simpler because it involves less overhead.

  • Object data update is slower and more complex because it involves more overhead.

  • Example of primitive data update: x = 5; y = true;

  • Example of object data update: myArray[...read more

Q73. Show reflection in java.

Ans.

Reflection in Java allows inspection and modification of runtime behavior of a program.

  • Reflection is achieved through classes in the java.lang.reflect package.

  • It allows access to class information, constructors, methods, and fields at runtime.

  • Reflection can be used to create new objects, invoke methods, and access or modify fields.

  • Example: Class c = Class.forName("java.lang.String");

  • Example: Method m = c.getDeclaredMethod("substring", int.class);

Q74. Operation on stack , queue , tree and best solution and optimized code

Ans.

Optimized code for stack, queue, and tree operations.

  • For stack operations, use an array or linked list and implement push, pop, and peek functions.

  • For queue operations, use a circular buffer or linked list and implement enqueue, dequeue, and peek functions.

  • For tree operations, use recursion and implement traversal algorithms such as inorder, preorder, and postorder.

  • Optimize code by reducing unnecessary operations and using appropriate data structures.

  • Examples: Implementing a ...read more

Q75. Operation on the Linked List and time complexity , Operation on the Array and time complexity

Ans.

Operations on Linked List and Array with their time complexities.

  • Linked List operations: insertion (O(1)), deletion (O(1)), traversal (O(n)), search (O(n))

  • Array operations: insertion (O(n)), deletion (O(n)), traversal (O(n)), search (O(n))

  • Arrays have constant time access to elements while linked lists don't.

  • Arrays are better for random access while linked lists are better for sequential access.

Q76. Swap a number without any temporary variables and pointers.

Ans.

Swapping numbers without temporary variables or pointers.

  • Use addition and subtraction to swap values

  • For example, a = a + b; b = a - b; a = a - b;

  • Another method is to use XOR bitwise operator

  • For example, a = a ^ b; b = a ^ b; a = a ^ b;

Q77. Why SDE 1 only not SDE 2

Ans.

SDE 1 is an entry-level position where candidates gain foundational skills before advancing to SDE 2.

  • SDE 1 focuses on learning and building foundational skills in software development.

  • SDE 2 requires more experience and expertise in software development.

  • Advancing from SDE 1 to SDE 2 is a common career progression in tech companies.

  • SDE 1 roles often involve working on smaller projects or components of larger projects.

  • SDE 2 roles typically involve leading larger projects or team...read more

Q78. Implementing a feature in REACT

Ans.

Implementing a feature in REACT

  • Identify the feature requirements and design the component structure

  • Write the necessary JSX code to create the feature

  • Implement state management using React hooks or Redux if needed

  • Handle user interactions and update the component state accordingly

  • Test the feature to ensure it works as expected

Q79. Internal working of HashMap?calculation part also

Ans.

HashMap is a data structure that stores key-value pairs and uses hashing to efficiently retrieve values.

  • HashMap uses an array of linked lists to store key-value pairs.

  • When a key-value pair is added, the key is hashed to determine the index in the array where it will be stored.

  • If multiple keys hash to the same index (collision), a linked list is used to store all key-value pairs at that index.

  • To retrieve a value, the key is hashed again to find the index and then the linked li...read more

Q80. Coding question 1. Find maximum subarray

Ans.

Maximum subarray problem is to find the contiguous subarray with maximum sum in an array of integers.

  • Use Kadane's algorithm to find the maximum subarray sum in linear time complexity.

  • Initialize two variables, max_so_far and max_ending_here, to track the maximum sum so far and the maximum sum ending at the current index, respectively.

  • Iterate through the array and update max_ending_here and max_so_far accordingly.

  • Return max_so_far as the maximum subarray sum.

Q81. Write a code to display data in tabel format

Ans.

Code to display data in table format

  • Use HTML table tags

  • Loop through data to populate table cells

  • Apply CSS for styling

Q82. Different containers in STL

Ans.

STL provides various containers like vector, list, map, set, etc.

  • Vector: Dynamic array with contiguous memory allocation

  • List: Doubly linked list

  • Map: Associative container with key-value pairs

  • Set: Associative container with unique keys

  • Deque: Double-ended queue

  • Stack: LIFO data structure

  • Queue: FIFO data structure

Q83. Round 2: Low level design. Design a lift system.

Ans.

Design a lift system

  • Determine the number of floors and the maximum weight capacity

  • Choose the type of lift system (hydraulic, traction, etc.)

  • Design the control system for the lift (buttons, sensors, etc.)

  • Consider safety features such as emergency brakes and backup power supply

Q84. Overloading vs Overriding

Ans.

Overloading is having multiple methods with the same name but different parameters. Overriding is having a method in the subclass with the same name and parameters as in the superclass.

  • Overloading is compile-time polymorphism while overriding is runtime polymorphism.

  • Overloading is used to provide different ways of calling the same method while overriding is used to provide a specific implementation of a method in the subclass.

  • Overloading is achieved within the same class whil...read more

Q85. Polymorphism with Example

Ans.

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 of the same class.

  • Polymorphism is achieved through method overriding and method overloading.

  • Method overriding is when a subclass provides its own 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.

  • Example of polymorphism: A...read more

Q86. Print pair with given sum.

Ans.

Given an array of integers and a target sum, find a pair of integers that add up to the target sum.

  • Create a hash table to store the difference between the target sum and each element in the array

  • Iterate through the array and check if the current element is present in the hash table

  • If it is, return the current element and its corresponding hash table value as the pair that adds up to the target sum

  • If no such pair is found, return null or an empty array

Q87. 4 pillars of oops , tcp ip model ,osi model

Ans.

4 pillars of OOPs are Abstraction, Encapsulation, Inheritance, and Polymorphism. TCP/IP and OSI models are networking models.

  • Abstraction: Hiding implementation details and showing only necessary information.

  • Encapsulation: Binding data and functions together and restricting access to them.

  • Inheritance: Creating new classes from existing ones, inheriting their properties and methods.

  • Polymorphism: Ability of objects to take on multiple forms or behaviors.

  • TCP/IP model: Consists of...read more

Q88. What is bubble sort time complexity, Code it

Ans.

Bubble sort has a time complexity of O(n^2)

  • Bubble sort compares adjacent elements and swaps them if they are in the wrong order

  • It repeats this process until the array is sorted

  • It has a worst-case time complexity of O(n^2) and a best-case time complexity of O(n)

  • It is not efficient for large datasets

Q89. What is closure in JS?

Ans.

Closure is a function that has access to its outer function's variables, even after the outer function has returned.

  • Closure is created when a function returns another function.

  • The inner function has access to the outer function's variables.

  • Closure is used to create private variables and methods.

  • Example: function outer() { let x = 10; return function inner() { console.log(x); } }

  • Example: let closureFunc = outer(); closureFunc(); // Output: 10

Q90. Find missing number in array without extra space

Ans.

Find missing number in array without extra space

  • Iterate through the array and XOR all the elements with their indices and the actual numbers

  • The missing number will be the XOR result

  • Example: ['1', '2', '4', '5'] -> XOR(0, 1) ^ XOR(1, 2) ^ XOR(2, 4) ^ XOR(3, 5) = 3

Q91. check whether a linked list is palindrome

Ans.

Check if a linked list is palindrome

  • Traverse the linked list and push each element onto a stack

  • Traverse the linked list again and compare each element with the top of the stack

  • If all elements match, the linked list is a palindrome

Q92. Get all permutations of an array.

Ans.

Get all permutations of an array.

  • Use recursion to swap elements and generate permutations

  • Iterate through the array and swap elements at each index

  • Use a set to avoid duplicates

Q93. What is encapsulation?

Ans.

Encapsulation is the process of hiding implementation details and exposing only necessary information to the user.

  • Encapsulation is achieved through access modifiers like public, private, and protected.

  • It helps in achieving data abstraction and information hiding.

  • Encapsulation provides better control over the data and prevents unauthorized access.

  • Example: A class with private variables and public methods to access those variables.

  • Example: A capsule that contains medicine and o...read more

Frequently asked in, ,

Q94. Why strings are immutable

Ans.

Strings are immutable to ensure data integrity and prevent unintended changes.

  • Immutable strings allow for safer multithreading and concurrency.

  • String interning is possible because of immutability.

  • Immutable strings can be used as keys in dictionaries and hash tables.

  • Examples of immutable data types include numbers and tuples.

Q95. N queens problem. Minimum steps by knight.

Ans.

The N Queens problem is to place N chess queens on an NxN board so that no two queens threaten each other. Minimum steps by knight is a variation of this problem.

  • The N Queens problem is a classic problem in computer science and can be solved using backtracking.

  • The minimum steps by knight variation involves placing N knights on an NxN board so that no two knights threaten each other.

  • This problem can also be solved using backtracking and can be optimized using heuristics such a...read more

Q96. reverse the link list

Ans.

Reverse a linked list

  • Iterate through the linked list and reverse the pointers

  • Use three pointers - prev, current, next to reverse the links

  • Update the head of the linked list to the last node after reversing

Q97. what is hobbee ? what you like

Ans.

Hobbee is a term that doesn't have a specific meaning. It can be used to refer to a hobby or interest.

  • Hobbee can be anything that someone enjoys doing in their free time

  • It can be a sport, a craft, a game, or any other activity

  • For example, someone's hobbee might be playing guitar, hiking, or reading

  • The term is often used in a casual or playful way to ask someone about their interests

Q98. Algorithm for string attachment

Ans.

String attachment algorithm joins two strings together.

  • Create a new string variable to hold the result

  • Loop through the first string and add each character to the new string

  • Loop through the second string and add each character to the new string

  • Return the new string

Q99. Explain one machine learning algorithm.

Ans.

Random Forest is a machine learning algorithm that builds multiple decision trees and combines their outputs.

  • Random Forest is an ensemble learning method.

  • It builds multiple decision trees and combines their outputs to make a final prediction.

  • It is used for both classification and regression tasks.

  • It is less prone to overfitting compared to a single decision tree.

  • It can handle missing values and outliers.

  • Example: predicting whether a customer will buy a product based on their ...read more

Q100. How to use set in javascript

Ans.

Sets in JavaScript are used to store unique values of any type.

  • Create a new set using the Set constructor

  • Add values to the set using the add() method

  • Check if a value exists in the set using the has() method

  • Remove a value from the set using the delete() method

  • Iterate over the set using the forEach() method

Previous
1
2
3
4
Next
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.9
 • 7.8k Interviews
4.1
 • 4.9k Interviews
4.4
 • 811 Interviews
3.3
 • 737 Interviews
3.5
 • 188 Interviews
2.8
 • 51 Interviews
3.3
 • 50 Interviews
View all

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

Sde1 Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter