https://www.interviewbit.com/old/problems/is-rectangle/ int Solution::solve(int A, int B, int C, int D) { if (((A==B)&&(C==D))||((A==C)&&(B==D))||((A==D)&&(B==C))){ return 1; }else{ return 0; } }
Given an sorted array A of size N . Find number of elements which are less than or equal to B . int Solution::solve(vector<int> &A, int B) { int start=0; int ans=0; int end=A.size()-1; while(start<=end) { int mid=(end+start)/2; if(A[mid]<=B) { ans=mid+1; start=mid+1; } else{ end=mid-1; } } return ans; }
https://www.hackerrank.com/challenges/game-of-stones-1/problem?h_r=internal-search string gameOfStones ( int n ) { string ans = "" ; if ( n % 7 == 0 || n % 7 == 1 ) ans += "Second" ; else ans += "First" ; return ans ; }
Comments
Post a Comment