Skip to main content

Posts

Samsung R&D Coding Question

 Q). => Coding: #include<iostream> using namespace std; int subsetSum(int a[],int len){ int sum=0,maxSum=0; for(int i=1;i<=len;i++){     for(int j=0;j<=len-i;j++){        for(int k=0;k<i;k++){          sum=sum+a[j+k];        }         if(sum>maxSum){           maxSum=sum;         }         sum=0;      } } return maxSum; } int main(){ int n; cout<<"Enter the size of the array\n"; cin>>n; int a[n]; cout<<"Enter Array size : \n"; for(int i=0;i<n;i++){     cin>>a[i]; } int r=subsetSum(a,n); cout<<"result "<<r<<endl; } => Output:
Recent posts

Blume Global Inc Coding Question in c++

 =>Bitwise Queries => Coding  #include<iostream> #include<vector> using namespace std; vector<int> myQuery(int N,vector<int> A,vector<vector<int>> queries){ vector<int> my; int fVal,X,Y,counter=0; for(int i=0;i<queries.size();i++){           X=queries[i][0];           for(int k=0;k<N;k++){             fVal=2*(A[k]|X)-(A[k]^X);             Y=queries[i][1];             if(fVal>=Y){                 counter++;             }           }           my.push_back(counter);           counter=0; } cout<<"\n**Result***\n\n"; return my; } int main(){     int n,q,val,qVal;     cout<<"Enter the size of the array :";     cin>>n;     vector<int> arr;     for(int i=0;i<n;i++){         cin>>val;         arr.push_back(val);     }     cout<<"Enter the size of the query :";     cin>>q;     vector<vector<int>> query;     for(int i=0;i<q;i++){         vector<int

Two Sum Problem

  Question 1 Given an array of integers   nums  and an integer   target , return   indices of the two numbers such that they add up to  target . You may assume that each input would have  exactly  one solution , and you may not use the  same  element twice. You can return the answer in any order.   Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Output: Because nums[0] + nums[1] == 9, we return [0, 1]. Example 2: Input: nums = [3,2,4], target = 6 Output: [1,2] Example 3: Input: nums = [3,3], target = 6 Output: [0,1]   Constraints: 2 <= nums.length <= 10 4 -10 9  <= nums[i] <= 10 9 -10 9  <= target <= 10 9 Only one valid answer exists.   Follow-up:  Can you come up with an algorithm that is less than  O(n 2 )  time complexity? ******************************** Time Complexity (O(n^2)) ******************************** => Coding  vector<int> twoSum(vector<int>& nums, int target) {               vector<int> twoSum;           

Capgemini Coding Q1

 Q). => Solution : #include<iostream> #include<vector> #include<algorithm> using namespace std; vector<int> removeDupMerge(int a1[],int a2[],int m,int n){ vector<int> mVec; for(int i=0;i<m-1;i++){      if(a1[i]!=a1[i+1])         mVec.push_back(a1[i]); } mVec.push_back(a1[m-1]); for(int i=0;i<n-1;i++){      if(a2[i]!=a2[i+1])         mVec.push_back(a2[i]); } mVec.push_back(a2[n-1]); sort(mVec.begin(),mVec.end()); return mVec; } int main(){ int m,n; vector<int> myVec; cin>>m; int a1[m]; for(int i=0;i<m;i++)     cin>>a1[i]; cin>>n; int a2[n]; for(int i=0;i<n;i++)     cin>>a2[i]; sort(a1,a1+m); sort(a2,a2+n); cout<<"\n\n*******| OUTPUT |*******\n\n"; myVec=removeDupMerge(a1,a2,m,n); //find median int median,sVec=myVec.size(); if(sVec%2==0){     median=(sVec-1)/2 + sVec/2; }else{     median=(sVec-1)/2; } cout<<myVec[median]<<endl; } =>Output :

New Year Chaos(HackerRank Question)

 Question) *********************************************************************************** =>Solution :

Hexadecimal Number To Decimal Number Using C++ ( With Condition Check)

 => Program : #include<iostream> #include<math.h> using namespace std; string low2up(string passStr){ string changeStr=passStr; for(int i=0;i<changeStr.size();i++){      if(passStr[i]>=97 && passStr[i]<=122)       { changeStr[i]=changeStr[i]-32;       } } return changeStr; } bool validHexVal(string checkSr){ bool checkValid; int countNum=0; for(int i=0;i<checkSr.size();i++){      if(checkSr[i]>=65 && checkSr[i]<=70)       { countNum++;       }       if(checkSr[i]>=48 && checkSr[i]<=57){         countNum++;       } } if(checkSr.size()==countNum){     return true; }else{     return false; } } int main(){ int decNum=0,val; string hexNum,upperHexNum; cout<<"Enter the hex decimal number "<<endl; cin>>hexNum; upperHexNum=low2up(hexNum); int n=upperHexNum.size(); if(validHexVal(upperHexNum)){  for(int i=n-1;i>=0;i--){     if(upperHexNum[i]>=65 && upperHexNum[i]<=70)       { val

Decimal Number To Hexadecimal Number Using C++

  => Program : #include<iostream> #include<math.h> using namespace std; int main(){ int decNum,rem,i=0; cout<<"Enter the Decimal Number : "<<endl; cin>>decNum; char hexVal[100]; while(decNum){    rem=decNum%16;    if(rem<10){      hexVal[i++] = 48 + rem;    }else{      hexVal[i++] = 55 + rem;    }   decNum=decNum/16; } cout<<"HEXA DECIMAL NUMBER : "; for(int j=i-1;j>=0;j--){     cout<<hexVal[j]; } cout<<endl; } => Output :