Nagarro
10+ Diyan Corporation Interview Questions and Answers
Q1. Count Ways To Reach The N-th Stair Problem Statement
You are given a number of stairs, N
. Starting at the 0th stair, you need to reach the Nth stair. Each time you can either climb one step or two steps. You ha...read more
Q2. Trailing Zeros in Factorial Problem
Find the number of trailing zeroes in the factorial of a given number N
.
Input:
The first line contains an integer T
representing the number of test cases.
Each of the followi...read more
Q3. Convert First Letter to Upper Case
Given a string STR
, transform the first letter of each word in the string to uppercase.
Example:
Input:
STR = "I am a student of the third year"
Output:
"I Am A Student Of The...read more
Q4. What is Decorator, what is binary tree, what is difference between tree and binary tree , about hash map
Decorator is a design pattern that allows behavior to be added to an individual object, either statically or dynamically.
Binary tree is a tree data structure in which each node has at most two children.
A tree is a data structure consisting of nodes connected by edges. A binary tree is a specific type of tree with at most two children per node.
A hash map is a data structure that maps keys to values for efficient lookup.
Q5. Quick and merge time complexity and when worst case happens in quick sort
Quick sort has O(n log n) time complexity on average, O(n^2) worst case. Merge sort has O(n log n) time complexity always.
Quick sort has an average time complexity of O(n log n) due to its divide-and-conquer approach.
Worst case for quick sort occurs when the pivot element is either the smallest or largest element in the array, leading to O(n^2) time complexity.
Merge sort always has a time complexity of O(n log n) due to its consistent splitting and merging of subarrays.
Q6. Remove a linked list node without head or tail pointer given
Removing a node from a linked list without head or tail pointer
Use the node to be removed's next node to copy its data and then delete the next node
Update the current node's next pointer to skip the next node
Q7. How to find largest element in array with O(N) complexity
Iterate through array once, keeping track of largest element found so far.
Initialize a variable to store the largest element found so far
Iterate through the array and update the variable if a larger element is found
Return the largest element after the iteration is complete
Q8. which Programming language will you prefer HashMap and internal working of HashMap String pool loop in a Linked list Oops Concept real type of problem
I would prefer Java for its versatility and widespread use in software development.
Java is a popular programming language known for its flexibility and scalability.
HashMap is a data structure in Java that stores key-value pairs and uses hashing to efficiently retrieve values.
String pool in Java is a pool of unique string literals stored in memory to optimize memory usage.
Looping through a Linked List involves iterating through each node in the list until reaching the end.
Obje...read more
Q9. Your favorite programming language and why
My favorite programming language is Python because of its simplicity, readability, and versatility.
Python is known for its clean and readable syntax, making it easy to learn and understand.
Python has a large standard library and many third-party libraries, allowing for rapid development of a wide range of applications.
Python is versatile and can be used for web development, data analysis, machine learning, automation, and more.
Q10. Discuss space and time complexity of Linked list traversals
Space complexity of linked list traversal is O(1) and time complexity is O(n)
Space complexity is constant as we only need a few extra pointers to traverse the list
Time complexity is linear as we need to visit each node in the list once
Example: Traversing a singly linked list from head to tail requires O(n) time complexity
Q11. What is multi threading?
Multi threading is a programming concept where multiple threads within a process execute independently to improve performance.
Allows for concurrent execution of tasks within a single process
Improves performance by utilizing multiple CPU cores
Requires careful synchronization to avoid race conditions
Examples include web servers handling multiple requests simultaneously
Q12. Remove nth element from array
Remove the nth element from an array of strings
Use the splice method to remove the element at the specified index
Remember that array indices start at 0
Example: array.splice(n, 1) will remove the element at index n
Q13. Find loop on linkedin list
To find a loop in a linked list, use Floyd's Cycle Detection Algorithm.
Use two pointers, slow and fast, to traverse the linked list.
If there is a loop, the fast pointer will eventually meet the slow pointer.
Example: 1->2->3->4->5->2 (loop back to 2)
Q14. Reverse string in java
Reverse a string in Java using StringBuilder
Create a StringBuilder object with the input string
Use the reverse() method of StringBuilder to reverse the string
Convert the StringBuilder object back to a string using toString()
Q15. Implement Stacks and Queues
Implement Stacks and Queues using arrays
For implementing a Stack, use an array and keep track of the top element
For implementing a Queue, use an array and maintain front and rear pointers
Example: Implementing a Stack using an array - push elements onto the top and pop elements from the top
Example: Implementing a Queue using an array - enqueue elements at the rear and dequeue elements from the front
Q16. 2. Find Kth smallest element.
Use quickselect algorithm to find the Kth smallest element in an array.
Implement quickselect algorithm to efficiently find the Kth smallest element.
Partition the array around a pivot element and recursively search in the appropriate partition.
Time complexity of quickselect is O(n) on average, making it efficient for finding Kth smallest element.
Q17. Write a program for calculator
A simple calculator program that can perform basic arithmetic operations
Create functions for addition, subtraction, multiplication, and division
Take user input for numbers and operation choice
Display the result of the operation
Q18. Write a program
Program to sort an array of strings in alphabetical order
Use a sorting algorithm like bubble sort or quicksort
Compare adjacent strings and swap if necessary
Repeat until the array is sorted
More about working at Nagarro
Top HR Questions asked in Diyan Corporation
Interview Process at Diyan Corporation
Top Associate Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month