Category : algorithm

I am trying to solve a problem: There is a survey that consists of n questions where each question’s answer is either 0 (no) or 1 (yes). The answers of the students are represented by a 2D integer array students where students[i] is an integer array that contains the answers of the ith student (0-indexed) ..

Read more

You are given a read only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and B which is missing. Return A and B. Here is the solution tried : vector<int> Solution::repeatedNumber(const vector<int> &A) { int n=A.size(); vector<int> res(2); unordered_map<int, int> m; for(int i=0;i<n;i++){ m[A[i]]++; if(m[A[i]]==2) ..

Read more