Codility is the coding environment most businesses use to evaluate prospective software engineers. The program aids recruiters in developing original questions, detecting instances of plagiarism, and recording the amount of time spent on each assignment. This application allows employers to conduct online interviews with candidates, run unit tests, compile code, and generate performance reports.
Using Codility, recruiters and hiring managers can tailor workflows to the skills of each prospect and then follow up with qualified applicants via phone screening. Businesses can utilize the tool to organize and manage code issues, thereby enhancing their brand’s reputation. This article will provide you with the top 25 Codility interview questions and sample responses to help you prepare.
1. Why Are You Interested In Applying For This Position With Our Company?
As your employee, I will enjoy numerous benefits. Long-term employment at Microsoft will have a substantial effect on my career for a variety of reasons. I’m driven to contribute to the future growth of your company because of its lengthy and prosperous history. In addition, the originality of your company’s products will enable me always to learn something new and apply it in the future to reach new heights.
2. Which Three Qualities Do You Consider Are Necessary For Employment At Our Company?
As I observed from my research, a valuable team member with a strong dedication to the project is crucial. They are employed to comprehend and support employees and treat everyone with the same degree of dignity and respect. Your company’s guiding principle is treating everyone equally in the workplace. A person must now possess and know this to implement it in their employment, should they be recruited. Everyone’s comments should be appreciated and considered if they are made with a cooperative spirit and with other coworkers. Your company’s success can be largely attributable to its dedication to fostering a healthy work environment.
3. Describe An Occasion When You Took A Risk At Work.
While working on a project with a tight deadline and a problem that needed to be fixed by a coworker, I worked on weekends to comprehend the project’s needs and meet the deadline. Not only was I able to accomplish the project within the allotted time, but I also avoided placing my partner at risk and prevented a major loss for the company.
4. What Exactly Is An “Array”?
An array is a collection of elements of the same data type stored in contiguous memory regions. It makes it simpler to determine the position of each element by adding an offset to a base value, i.e., the memory location of the array’s first element (generally denoted by the array’s name). The starting index is 0, and the difference between the two indexes is the offset.
5. Given An Array Of Integers And A Value, Determine Whether Or Not There Are Any Two Integers In The Array Whose Sum Equals The Value The User Has Provided.
There are primarily two ways to approach fixing this issue:
- By brute Force: The most straightforward approach is to examine each pair in the provided array and return true if the required sum is reached at any point during the process.
- Using Sorting: The objective is to sort the array in ascending order while conserving search space by maintaining two indices that point to the array’s two endpoints. Then, reduce the search space num[low…high] for each loop iteration by comparing the sum of elements present at indices low and high to the desired sum. If the total is less than the expected total, increase low; if the total is larger than the desired total, increment high. If the pair is found, it is returned.
6. What Exactly Is A Sorting Algorithm?
A sorting algorithm is a method for restructuring many things into a certain order, such as alphabetical, greatest-to-least value, or shortest-to-greatest distance. Sorting algorithms accept item lists as input, conduct certain actions on those lists, and output arrays in an ordered state. Sorting algorithms have numerous applications, such as grouping products by price on a retail website and deciding the order of pages on a search engine results page (SERP).
7. If Any Element Of The Provided Array Is 0, Set The Entire Row And Column To Zero.
The most obvious method is to scan the two-dimensional matrix and set the entire column and row to zero if a zero is present. This answer, however, is erroneous. Even if the matrix contains a single zero, the entire matrix will be zero.
Scanning the 2D array for all rows and columns that contain zero and dividing them into two sets would be one method I would employ.
8. How Do You Define Classes And Objects In C++?
User can build their classes, which are then implemented as data types with member functions and data members. The members of the data are the variables that are contained within the data. And the member functions are the operations that are performed on those variables. An instance of a class is referred to as an object. Because an object is a user-defined data type, it can be referred to as a variable within a class.
9. Do You Believe OOOP Is An Effective Coding Method?
Object-oriented programming (OOP) has been the dominant paradigm for decades, but whether this was due to merit or chance is debatable. Data-oriented programming (DOP) has recently gained popularity and can be utilized greatly in numerous fields.
10. Given An Array Of Positive Numbers Ranging From 1 To N, With All But One Instance Of ‘X’ Present, Determine The Value Of X. You Should Locate ‘X.’ There Is No Sorting In The Input Array.
I would utilize the arithmetic series sum formula: Sum(1 – n) = n(n+1)n(n+1).
Following are the steps for locating the missing number:
- Using the sum of elements’ variables, find the sum of all the numbers in the array. According to O, this would demand a linear scan (n).
- Determine the sum ‘expected sum’ of the first ‘n’ values using the arithmetic series sum formula (n * (n + 1)) / 2.
- The missing value in the array is the difference between the expected sum and the sum of elements, or ‘expected sum – the sum of elements.
11. How Do You Determine The Largest And Smallest Numbers In A 1–100 Array?
- I would initially generate an array of all integers between 1 and 100.
- Accordingly, initialize a variable for the largest and smallest numbers discovered to date with the smallest and largest integers.
- Iterate through each value in the array and use Max and Min to determine whether it is greater or less than the numbers previously recorded.
- These values contain the array’s greatest and smallest numbers.
12. What Differentiates A Programming Language From A Script?
A programming language is compiled before execution, meaning it is translated to machine code that the computer can read directly. However, scripting languages are interpreted in real-time by the computer.
13. What Exactly Is Meant By “Stream Pipelining”?
The process of chaining together several different activities is known as stream pipelining. This function is accomplished via pipelining, which does so by separating stream operations into two distinct categories: intermediate operations and terminal operations. After the execution of each intermediate operation, it will return an instance of the stream. As a result, a user can construct a processing pipeline consisting of intermediate activities, regardless of how many such operations are put up.
It is necessary for there to be a terminal operation at the very end of the process to return a final value and put an end to the pipeline.
14. How Is The Number Of Vowels And Consonants In A String Calculated?
To calculate the number of vowels in a string, I would:
- Convert the string to lowercase to simplify the checks.
- Then iterate over every character in the string.
- Check each vowel individually, as the set is small.
- If it is not a vowel, I would then determine if its ASCII value falls within the range of all known letters (as a character is ultimately a numerical value).
15. What’s The Difference Between An Array And A Linked List?
Both are collections containing data of types comparable to one another; however, the mechanism in which the data is stored is different between the two. Data is stored in an array in the memory at contiguous locations; however, in a linked list, each element carries a reference to the element that comes after it.
16. How Should A Binary Search Tree Be Implemented?
A binary search tree is a tree data structure consisting of nodes, with each node containing a maximum of two linking nodes, commonly referred to as Left and Right. A binary search tree can be implemented entirely as a single Node class containing the data and references to the Left and Right nodes in its simplest form.
17. How Can I Locate Duplicate Numbers In An Array Containing Multiple Duplicates?
- Create a dictionary with the number as the key and the frequency of its occurrence as the value.
- Iterate through the array and increment the key’s count in the dictionary.
- Finally, iterate through all pairs in the dictionary, duplicating the value in the array if it is more than 1.
18. What Exactly Is A Stream, And How Is It Different From A Collection?
A stream is an iterator whose purpose is to accept a collection of actions and apply them to each item. A stream is a succession of objects from a collection or other source that allows aggregate operations. In contrast to collections, iteration logic is implemented within a stream. Moreover, unlike collections, streams are automatically loaded and processed lazily.
19. How Do You Traverse A Specified Binary Tree In Preorder Without Recursion?
I would take the following steps:
- Utilize a stack for depth-first processing.
- The initial node (often the root) is pushed onto the stack.
- Use a while loop to perform processing until the stack is empty.
- Read the node at the top of the stack.
- Take this off the stack.
- If the node has a Left or Right attribute, add it to the stack.
- The loop will continue adding and processing nodes until the entire tree has been processed, at which point the stack will be empty, and the loop will end.
20. If You Are Given A String, Find All Palindrome Substrings Containing More Than One Letter.
To begin our search for palindromes of even and odd lengths, we begin by extending to the left. And right for each letter in the input string. Move on to the next letter if we already know there isn’t a palindrome in the word. We analyze and develop one character compared to the character on their left and right. If both are the same, then we can print the palindrome substring.
21. Determine The Location In An MXM Grid Where N Persons Can Meet With The Shortest Total Distance Traveled.
We use a ‘centroid’ to find the shortest distance.
The Centroid is the arithmetic mean or an average of two-dimensional points. The Centroid of all the sites on the grid with people will be the shortest distance. The formula is: centroid = (x1+x2+x3…+xn , y1+y2+y3…+yn).
In most cases, the Centroid is the correct answer, but it’s the nearest point on unusual occasions. We’ll find the Centroid first, then examine the eight places around it for the least distance traveled. The minimal distance traveled point is any site farther than the Centroid.
Because we average all the points and round off the figure, the Centroid is sometimes erroneous. It almost usually produces a correct center point. The nearest point may be at any input location, which Centroid cannot determine. We double-check the “closest point’s” neighbors.
22. We Have A 2D Array With Sorted Rows And Columns. We Must Locate A Key In A Matrix.
Scan the 2D array for the key in O(mn) time. Using a matrix’s sorted attribute can be faster. Perform a binary search on each row to see if the key exists. This solution is O(m*logn). We have a better response; however, it’s lovely.
We compare the upper right matrix corner to the key. If it matches, we’ve found the key. If it is smaller than the element, we shift left; if it is higher, we move down one position.
Because the matrix is sorted, moving left will decrease values, and moving right will increase them. Repeat until we discover the element or reach the matrix’s border. This technique visits m + n matrix elements, taking O(m + n) time.
23. Join The Sibling Pointer To The Node At The Same Level. The Last Node Of Each Class Should Point To The Initial Node Of The Tree’s First Level.
A binary tree is a data structure composed of nodes, each of which has a “left” and “right” reference in addition to a data element. The root is the most central node in a tree. Each node, excluding the ‘root’ node, is connected to another node through a directed edge. This node is known as the parent of that node. On the other hand, each node can be connected to an infinite number of children. Nodes that share the same parent node are siblings.
In addition to the left and right pointers, each node in the preceding binary tree includes an additional pointer. Next, is the command used to connect two nodes. Once siblings are related, a linked-list-like structure with the root node as the head is formed. Two pointers are maintained: current and previous. The current node is the one being worked on, whereas the last node is the one that has been constructed.
24. How Do You Determine Whether A Loop Exists In A Singly-Linked List?
A loop (or cycle) in a linked list occurs when the next value of a node points back to an earlier node. To determine if a loop exists in a singly linked list, I would:
- Create a set of hashed nodes. I use this to determine whether a node has already been handled.
- I then review the linked list, appending each node to the hash set.
- The linked list contains a loop if the node already exists in the hash set (or cycle).
25. Return The Buy And Sell Prices That Will Provide The Greatest Profit From A Daily List Of Stock Prices (Integers For Simplicity). Maximizing The Single Buy/Sell Profit Is Required. If You Cannot Make Money, You Should Attempt To Minimize Your Losses As Much As Possible.
We should utilize Kadane’s algorithm in this situation. The values of the array represent the daily price of a stock. Since we can only buy and sell the stock once, we must determine the best buy and sell prices that maximize our profit (or minimize our loss) over a given period.
This problem has a difficult linear solution that needs cycling through the entire array of stock prices while keeping the current buy price (the smallest value seen to date), current profit, and global profit. At each iteration, we will compare the current profit to the global profit and adjust the global profit accordingly.
In addition to the Codility test, you will also have an interview. It is a chance to establish rapport with the recruiter. If you can establish rapport with the interviewer, it will be easier to clarify your replies. Interview skills practice will make this phase easier. When describing your work to the interviewer, clear communication will reduce any unnecessary pressure you may feel.