f

DSA -2 Medium level || Mock Interview Question || Newton school mock Interview Question || Newton School DSA assignment solution || newton School








DSA –2 Medium Level (Mock Interview Questions ) 

Questions 

Rajat Goyal 

 

implement stacks using LL [Ans] 

 

Gaurav Saha 

 

longest common prefix in a string 

 

next greater element in array 

print the string with capital initial letters 

 

John Rabindranath 

 

whats are the different types of OOP's concepts 

what is polymorphism? explain 

what is inheritance? explain 

what are class and object? 

if Class A extends by Class B and Class b extends by Class C, whose constructor is needed to be called in class C? What type of Inheritance is that? 

what is a string? 

what is difference between concat() and + operator in string? 

what is a string constant pool? 

what are the different built in functions in string? 

what are linked list? explain different types of linked list? 

what are stack and queue? explain different operation in stacks and queue? 

what is stack.peek() in stack? 

Write a program using reverse a string? example: Jan o/p: naJ 

write a program to insert a node in the middle of a linked list (use custom linkedlist for better understanding) 

Where are the strings were stored? in stack or in heap memory? 

what is method overloading and method overriding? 

 

Sumit Saurav 

 

Longest substring without repeating charecter(leetcode) 

Add Two Linkedlist(leetcode) 

 

Sushant Thakur 

 

What is linkedlist and different types of linkedlist 

What are the differences between arrays and linkedlist 

WAP to add elements from array to linkedlist 

WAP to delete elements from linkedlist 

When should I use stack or queue over arrays/linkedlist 

Implement stack using linkedlist 

WAP to implement queue 

WAP to reverse the position of words in an arrays 

Differences between stack and queues 

WAP to check parenthesis are balanced or not 

 

santanu mohanty 

Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. 

2. Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array 

 

Pulkit Jain 

Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character. 

Note that after backspacing an empty text, the text will continue empty. 

Given the head of a singly linked list, return true if it is a palindrome. 

 

Tarun Pandey 

Swap the kth node from end of linked list [geeksforgeek] 

Rearrange list (even odd) [geeksforgeek] 

Palindorme string 

Linkedlist cycle( node from where the cycle starts) 

Flatten the double linkedlist with child pointer 

Remove duplicated from sorted linkedlist || 

 

Manish Shaw 

Given a string as an input. We need to write a program that will print all non-empty substrings of that given string. 

\ 

Examples : 

Input : abcd 

Output : a 

b 

c 

d 

ab 

bc 

cd 

abc 

bcd 

abcd 

Q.Longest Common Prefix using Word by Word Matching 

Given a set of strings, find the longest common prefix. 

Examples: 

Input : {“geeksforgeeks”, “geeks”, “geek”, “geezer”} 

Output : "gee" 

Input : {"apple", "ape", "april"} 

Output : "ap" 

Q.Move all occurrences of an element to end in a linked list 

 

Given a linked list and a key in it, the task is to move all occurrences of the given key to the end of the linked list, keeping the order of all other elements the same. 

Examples: 

Input : 1 -> 2 -> 2 -> 4 -> 3 

key = 2 

Output : 1 -> 4 -> 3 -> 2 -> 2 

Input : 6 -> 6 -> 7 -> 6 -> 3 -> 10 

key = 6 

Output : 7 -> 3 -> 10 -> 6 -> 6 -> 6 

 

Suraj Mall 

1. Intersection of Two Linked Lists(Leetcode) 
 

2.Valid Anagram(Leetcode) 
 

 

Love Arora 

 

1.Explain the Linked List data structure? 

2.What is difference between Doubly Linked List and Circular Linked List? 

3.Difference between Stack & Queue? 

4.Discuss any application of Doubly Linked List? 

5.Implement an algorithm, Given a singly linked list of characters, write a function that returns true if the given list is a palindrome, else false. 

LL: 1-> 2-> 2-> 1 

Output: true 

LL: 1-> 3>-4>->1 

Output: false 

6.Create LL without any library. 

 

Durga Chowdary Edara 

 

- What are Data Structures and Algorithms? How do you differentiate them? 

- What are Strings and what is String immutability? 

- Write a program for checking if a String is a Palindrome or not? 

- What are Linked Lists? How are they different from Arrays? 

- What is the difference between Single and Doubly Linked Lists? 

- Implement a program to add 1 to a number represented as a Linked List? 

Input - 9 -> 9 

Output - 1 -> 0 -> 0 

Input - 8 -> 7 -> 3 

Output - 8 -> 7 -> 4 

- What are stacks? What is the time complexity of pushing an element into the stack? 

 

Aman Jain 

 

Rotate list by K places 

Ashish Bhalala 

What are Data Structures ? 
What are the types of DS ? 
what is class, object? 
what is static, public, void? 
what is stack, queue. 
diff b/w array and linkedlist. 
 
WAP to find if string is palindrome or not? 
 
https://leetcode.com/problems/reverse-linked-list/ 

 

Rounak Goliya 

 

Question: Given a singly linked list, find the middle of the linked list. For example, if the given linked list is 1->2->3->4->5 then the output should be 3. 

If there are even nodes, then there would be two middle nodes, we need to print the second middle element. For example, if given linked list is 1->2->3->4->5->6 then the output should be 4. 

Question: Given a singly linked list of characters, write a function that returns true if the given list is a palindrome, else false. 

Question: Number is represented in linked list such that each digit corresponds to a node in linked list. Add 1 to it. For example 1999 is represented as (1-> 9-> 9 -> 9) and adding 1 to it should change it to (2->0->0->0) 

 

 

 

 

Kush Hingol 

 

1. What is a string as per your understanding 
2. Is string a dataType in Java? 
3. How many objects will be created for the below code 
String firstString = "Gaurav"; 
String secondString = "Gaurav"; 
String thirdString = new String("Gaurav"); 
 
4. Please provide the output for the below code 
 
public static void main(String[] args) { 
String firstString = "Gaurav"; 
String secondString = "Gaurav"; 
String thirdString = new String("Gaurav"); 
System.out.print("Case 1 : "); 
System.out.println(firstString == secondString); 
System.out.print("Case 2 : "); 
System.out.println(firstString == thirdString); 
 
System.out.print("Case 3 : "); 
System.out.println(firstString.equals(thirdString)); 
} 
 
5. Is string immutable or mutable? Why String is immutable? 
 
6. What is a linkedlist? 
7. What does each node of the LinkedList? 
8. What is doubly LinkedList 
9. Time complexity of insertion, deletion, traversing and searching in single linkedlist and doubly linkedlist 
 
10. Explain stack and queue 
 
DSA 
 
Given a string s, reverse only all the vowels in the string and return it. 
 
The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both cases. 
 
Input: s = "hello" 
Output: "holle" 
 
Input s = "oceian" 
Output: "acieon" 

 

 

Nikhil Arwindbhai Butani 

 

String Anagram 

Delete Kth node from LinkedList 

Implement queue 

Implement stack 

 

Hiren Patel 

 

i) what is data structure?? 

ii)What's algorithm?? 

1. whats string? 

2.What is Linked List? 

3.What is Stack and where it can be used? 

4.What is a Queue, how it is different from the stack? 

 

Hardik Singh 

1. Reverse a Linked List. 

 

Niraj Kumar 

 

1. What is string constant pool? 

2. How java manages memory for string. 

3. How many object will be created in both the statement. 

String str = "hello"; 

String str = new String("hello"); 

4. What is the basic difference between the == and .equals() 

5. You have given a string and a key, you have to find the number of time key has occurred in the string. 

String str = "heyone hey hello heyhey" 

key = "hey" 

output: 4 

6. iWhat s the basic difference between array and linked list? 

7. You have given 2 linked list , both are merging at one junction. Task is to find the element where both are merging. 

8. How to implement queue using stack. 

9. Given an expression string exp, write a program to examine whether the pairs and the orders of “{“, “}”, “(“, “)”, “[“, “]” are correct in exp. 

Input: exp = “[()]{}{[()()]()}” 

Output: Balanced 

Input: exp = “[(])” 

Output: Not Balanced 

 

Dev Mittal 

1. Implement a stack using an array. 

2. Next smaller number. 

 

Manish Shaw 

 

Q1. Program to print all substrings of a given string. 

Given a string as an input. We need to write a program that will print all non-empty substrings of that given string. 

Examples : 

Input : abcd 

Output : a 

b 

c 

d 

ab 

bc 

cd 

abc 

bcd 

abcd 

Q2. Longest Common Prefix using Word by Word Matching.s 

Given a set of strings, find the longest common prefix. 

Examples: 

Input : {“geeksforgeeks”, “geeks”, “geek”, “geezer”} 

Output : "gee" 

Input : {"apple", "ape", "april"} 

Output : "ap" 

 

Gurdeep Singh Mittal 

 

implement queue from stack 

 

 

Shubham Madheysia 

 

Write a function detectAndRemoveLoop() that checks whether a given Linked List contains a loop and if loop is present then removes the loop and returns true. If the list doesn’t contain a loop then it returns false. 

Example: 

Input: 1 ⇒ 2 ⇒3 ⇒ 4 ⇒ 5 ⇒ 6 ⇒ 3 

Output: 1 ⇒ 2 ⇒3 ⇒ 4 ⇒ 5 ⇒ 6 ⇒null 

Explanation: 6 is connected to 3 which makes 3 ⇒4 ⇒5 ⇒6 in loop 

Note: Write complete code and not just function. This would help us in running and debugging it effectively 

------------------------------------------ 

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. 

Input: s = "(()" 

Output: 2 

Explanation: The longest valid parentheses substring is "()". 

Input: s = "(()(()()" 

Output: 4 

Explanation: The longest valid parentheses substring is "()()". 

Input: s = "" 

Output: 0 

Note: You don’t have to count all valid pairs and sum it up. You need to hunt for the longest contiguous substring which is valid overall 

 

Nikhil Arvindbhai Butani 

 

String Anagram // completed 

Delete Kth node from LinkedList // completed (Few test cases not passed) 

Implement stack // completed 

implement queue // completed 

 

Dalchand Kumawat 

 

1. Check if there is a loop in linked list 

2. Check if two strings are anagrams. 

3. Implement queue using stack. 

 

Nikhil Devarasetty 

1. Given a string S, find the length of the longest substring without repeating characters. 

2. Remove loop in a single linked list 

3. Reverse alternate k nodes in a singly linked list 

kush hingol 

 

1. What is a string as per your understanding 

2. Is string a dataType in Java? 

3. How many objects will be created for the below code 

String firstString = "Gaurav"; 

String secondString = "Gaurav"; 

String thirdString = new String("Gaurav"); 

4. Please provide the output for the below code 

public static void main(String[] args) { 

String firstString = "Gaurav"; 

String secondString = "Gaurav"; 

String thirdString = new String("Gaurav"); 

System.out.print("Case 1 : "); 

System.out.println(firstString == secondString); 

System.out.print("Case 2 : "); 

System.out.println(firstString == thirdString); 

System.out.print("Case 3 : "); 

System.out.println(firstString.equals(thirdString)); 

} 

5. Is string immutable or mutable? Why String is immutable? 

6. What is a linkedlist? 

7. What does each node of the LinkedList? 

8. What is doubly LinkedList 

9. Time complexity of insertion, deletion, traversing and searching in single linkedlist and doubly linkedlist 

10. Explain stack and queue 

DSA 

Given a string s, reverse only all the vowels in the string and return it. 

The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both cases. 

Input: s = "hello" 

Output: "holle" 

Input s = "oceian" 

Output: "acieon" 

 

anirban paul 

 

delete the middle of the linked list. ( 2) if even delete two middle nodes if odd delete one middle node ..... only these two questions he is asking do slowly. 

Subham Jaishwal 

 

What is array , What is linked list , Stack , queue? 

2. diff between array and arrayList in java 

3. memory distribution for array , arrayList , LinkedList in java 

4. reverse words of string java using split and stack 

 

Shubham Bajpai 

reverse a linked list 

reverse a linked list in groups of K 

 

Rounak Goliya 

 

Question: Given a singly linked list, find the middle of the linked list. For example, if the given linked list is 1->2->3->4->5 then the output should be 3. 
If there are even nodes, then there would be two middle nodes, we need to print the second middle element. For example, if given linked list is 1->2->3->4->5->6 then the output should be 4. 
 
Question: Given a singly linked list of characters, write a function that returns true if the given list is a palindrome, else false. 
 
Question: Number is represented in linked list such that each digit corresponds to a node in linked list. Add 1 to it. For example 1999 is represented as (1-> 9-> 9 -> 9) and adding 1 to it should change it to (2->0->0->0) 

 

 

Mahima Yadav 

 

1)Explain linked list and different types of linked list -- Answered 
2)Explain how linked list is different from array -- Answered 
3)Write a program to implement queue using two stacks -- No knowledge 
4)A celebrity is a person who is known to all but does not know anyone at a party. If you go to a party of N people, find if there is a celebrity in the party or not. 
 
A square NxN matrix M[][] is used to represent people at the party such that if an element of row i and column j is set to 1 it means ith person knows jth person. Here M[i][i] will always be 0. 
 
Note: Follow 0 based indexing. 
 
Example 1: 
Input: 
N = 3 
M[][] = {{0 1 0}, 
{0 0 0}, 
{0 1 0}} 
 
Output: 1 
Explanation: 0th and 2nd person both 
know 1. Therefore, 1 is the celebrity. 
20 mins 
 
Example 2: 
Input: 
N = 2 
M[][] = {{0 1}, 
{1 0}} 
 
Output: -1 
 
Explanation: The two people at the party both know each other. None of them is a celebrity. 
-- Not solved 
Expected Time Complexity: O(N) 
Expected Auxiliary Space: O(1) 
 
5)Write a program to implement the stack using singly linked list -- not solved 

reverse words and it's char also 

ex , i have very bad luck 

kcul dab yrev evah i 

reverse linked list 

 

Shashank Chowdhary 

 

What is linked list and its types 
What is stack and queue 
Program to check string is palindrome or not 
Implement linked list and reverse it 

 

Ashim Kaushal 

1. Given a linked list, reverse it. 
2. Valid anagram - Leetcode. 
3. Given a string, remove all the occurrences of 'a' and 'z' from it. 
4. Given a string, count the no. of vowels in it. 

 

Utkarsh jain 

what is difference between array and linked list. 

Some question around linked list. 

 

Interviewer - Sathvik Bhandar  
Date - 6:00 pm - 6:55 pm, Aug 26th 2022 

 

 

1. Given a linked list detect if there a loop in the linked list or not. (Unable to answer) 
2. Given a linked list find the middle element of the linked list. (Correct with code) 
3. Given a linked list finr the k th element from the last. (Correct with code) 
 

 

Shivam Singh 

 

1.Explain string 
2.What is linked lists 
3.What are types of linked lists 
4.Explain each type in detail 
5.Write code to implement linked list and write logic to reverse it 

 

 

Dalchand kanwat 

1. Implement queue data structure. 

2. Identifying duplicates in linked list. 

 

pavan bhansali 

What is a Stack ? Push and pop implementation 

Write a program to create a linked list. 

Write a program to reverse the linked list. 

 

Soumya Pandith 

1. Explain multidimensional arrays 

2. types and difference between all types of linked list. 

3. Output of following code- 

String str = "Hi"; 

System.out.println(str+10+20); 

System.out.println(11+22+str); 

System.out.println(11+33+str+22+56); 

4. Coding question - Given a string, find the minimum number of characters to be inserted to convert it to palindrome. 

 

Mithun Kumar S R 

Given a stack of integers, how do you check whether each successive pair of numbers in the stack is consecutive or not. 

{ 1, 2, -1, -2, 4, 5, 90. 89, 50} 

 

 

Thompson Naidu 

1. Introduce yourself 
2. Implement a singly linked list data structure 
3. Given as a singly linked list, check if the linked list is a palindrome or not? 
4. What are the advantages of a linked list 

 

 

Nikhil Singh 

 

1.What will be the output of the following code snippet for the list 1->2->3->4->5->6? 
 
void solve(struct node* start) 
{ 
if(start == NULL) 
return; 
printf("%d ", start->data); 
if(start->next != NULL ) 
solve(start->next->next); 
printf("%d ", start->data); 
} 
2.Find the Next Greater Element for every node of the linked list. 
Note: For nodes with no next greater element, store -1 in the result. 
 
Examples: 
 
Input: linked list = [2, 1, 5] 
Output: [5, 5, -1] 
 
Input: linked list = [2, 7, 4, 3, 5] 
Output: [7, -1, 5, 5, -1] 
3. Remove duplicates from a sorted linked list. 
For example if the linked list is 11->11->11->21->43->43->60 then you should convert the list to 11->21->43->60. 

 

Shubham Bajpai  

1. Reverse singly Linked List ? 2. Merge 2 singly linked list ? 

 

 

 

Sourav Anand 

Take your full name as a string. 

Replace each character of the name by next character. A->B 

Input 

Abhishek 

Output 

Bcijtifl 

Input 

Saurav 

Output 

Tbvsbw 

 

Mandeep Kaur 

 

2) Implement a linked List with removeFromEnd function. 

String 

Link list 

Hasmaps 

Versa  

1) reverse a string using stack 

2) reverse a string without stack 

3) Program to Find the Middle Node of a Linked list 

 

shubham kucheria 

[ 1, 45, 5 ,7, 9 , 5] 

[ 2,1,5,6,1,9 ] 

Find only unique elements from these 2 arary . 

Output: [2, 6, 7, 45], 

Find length of linked list with less complexity, 

Find 15 elements of Fibonacci series. 

 

 

 

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.