# CodeGround Online Testing

Members

12

0 Neutral

• Rank
Member
1. ## MECE Framework

What is the MECE Framework? MECE stands for “Mutually Exclusive – Collectively Exhaustive” It is a structured problem-solving approach that forces you to list down all possible options without double counting. The Problem Statement is written down first. You must choose your words carefully while writing this down to ensure that there is no ambiguity in understanding the problem. The Options to solve the problem are then listed down in a tree-like fashion. The options must not overlap (Mutually exclusive) and no option must be missed out (Collectively exhaustive) Once the tree is built, the pros and cons of each path in the tree is discussed until the optimal solution path is decided. The MECE Framework can be used in case interview questions or in situational interview questions as discussed here: https://codeground.in/blog/index.php/2016/11/13/mece-framework-for-structured-thinking/ Was this useful? If you’re interested, you can read more about more such tips for Interview preparation ( https://codeground.in/blog/index.php/category/interview-preparation/ )or you can take do some online programming challenges ( https://codeground.in/screening-tests/coding-contests.html )
2. ## Count Inversions

What is an inversion? Let A be an array of n distinct numbers. If i < j and A > A[j], then the pair (i, j) is called an inversion of A. For example, the array {2,3,8,6,1} has 5 inversions: (2,1) (3,1) (8,6) (8,1) and (6,1) Trivial Solution to count the number of inversions in an array countInversions = 0; for i = 1 to N for j = i+1 to N if(A > A[j]) countInversions++; The overall time complexity for this approach is O(n^2) Using Merge Sort to count the number of inversions in O(n logn) time The approach using Merge Sort to count the number of inversions is detailed in this blog post ( https://codeground.in/blog/index.php/2016/11/13/technical-interview-question-on-data-structure-and-algorithms-count-the-number-of-inversions-in-an-array/ ). Was this useful? If you’re interested, you can read more about more such puzzles for Tech Interviews ( https://codeground.in/blog/index.php/category/interview-preparation/data-structures-algorithms-tech-interview-questions/ )or you can take do some online programming challenges ( https://codeground.in/screening-tests/coding-contests.html )
3. ## Cannibals and missionaries puzzle

Hi All, I found this interesting puzzle - Three missionaries and three cannibals must cross a river. There is a single boat which can carry a maximum of two people and there must be at least one person on board (the boat cannot cross by itself). On either bank, if there are missionaries present, the count of missionaries must be equal or greater than the count of cannibals, else the cannibals would eat them. This is a classic example of a puzzle that can be solved using state transition diagrams. The solution to this puzzle is detailed in this blog post: https://codeground.in/blog/index.php/2016/11/13/technical-interview-question-on-puzzles-missionaries-and-cannibals/ Was this useful? If you’re interested, you can read more about more such puzzles for Tech Interviews ( https://codeground.in/blog/index.php/category/interview-preparation/tech-interview-questions-puzzles/ )or you can take do some online programming challenges ( https://codeground.in/screening-tests/coding-contests.html )
4. ## Balance Puzzle

Hi All, I found this interesting puzzle - Three missionaries and three cannibals must cross a river. There is a single boat which can carry a maximum of two people and there must be at least one person on board (the boat cannot cross by itself). On either bank, if there are missionaries present, the count of missionaries must be equal or greater than the count of cannibals, else the cannibals would eat them. This is a classic example of a puzzle that can be solved using state transition diagrams. The solution to this puzzle is detailed in this blog post: https://codeground.in/blog/index.php/2016/11/13/technical-interview-question-on-puzzles-missionaries-and-cannibals/ Was this useful? If you’re interested, you can read more about more such puzzles for Tech Interviews ( https://codeground.in/blog/index.php/category/interview-preparation/tech-interview-questions-puzzles/ )or you can take do some online programming challenges ( https://codeground.in/screening-tests/coding-contests.html )

8. ## Perfect Shuffle

Hi All, I found the comparison between these two random shuffling algorithms to be interesting. Consider two shuffling algorithms SHUFFLE 1 shuffle(A[1 … n]) { for i = 1 to n { // Find a random integer between 1 and n inclusive int rand= RANDOM(1,n); swap A with A[rand]; } } SHUFFLE 2 shuffle(A[1 … n]) { for i = 1 to n { // Find a random integer between i and n inclusive int rand= RANDOM(i,n); swap A with A[rand]; } } How do these two shuffling algorithms compare against each other? Which of these two is a perfect shuffling algorithm? Consider an array with distinct elements A[1 … n] A perfectly unbiased shuffle algorithm would randomly shuffle all elements in the array such that after shuffling: 1.The probability that the shuffling operation would produce any particular permutation of the original array is the same for all permutations (i.e.) since there are n! permutations, the probability that the shuffle operation would produce any particular permutation is 1/n! 2.For any element e in the array and for any position j (1<= j <= n), the probability that the element would end up in position A[j] is 1/n Simulating Shuffle 1 and Shuffle 2 ( https://codeground.in/blog/index.php/2016/11/13/technical-interview-question-on-data-structures-and-algorithms-perfect-shuffle/ ) clearly proves that Shuffle 1 is biased while Shuffle 2 is unbiased Can we prove that Shuffle 2 will produce an unbiased shuffle in all cases? For any element e, the probability that it will be shuffled into the first position = probability that it is selected for swapping when i = 1 = 1/n For any element e, the probability that it will be shuffled into the second position = probability that it is NOT selected for the first position x probability that it is selected for swapping when i = 2 = (n-1)/n x 1/(n-1) = 1/n … For any element e, the probability that it will be shuffled into any particular position = 1/n Was this useful? If you’re interested, you can read more about Technical Interview questions on Data Structures and Algorithms ( https://codeground.in/blog/index.php/category/interview-preparation/data-structures-algorithms-tech-interview-questions/ ) or look at some programming challenges ( https://codeground.in/screening-tests/coding-contests.html )