Posts

Find all duplicates of array

     vector<int> duplicates(int arr[], int n) {         vector<int> dup(n);    //create a duplicate of array store occurance of element         vector<int> ans;       //store ans which occurs more than one times         for(int i=0;i<n;i++){             if(dup[arr[i]]==1)                {ans.push_back(arr[i]);}                           dup[arr[i]]++;         }         if(ans.size()){             sort(ans.begin(), ans.end());             return ans;         }        return {-1};              }

Encrypt the string - 1 Solution in cpp

Encrypt the string - 1 Solution in cpp GfG  problem solution in cpp PROBLEM STATEMENT:-  Bingu was testing all the strings he had at his place and found that most of them were prone to a vicious attack by Banju, his arch-enemy. Bingu decided to encrypt all the strings he had, by the following method. Every substring of identical letters is replaced by a single instance of that letter followed by the number of occurrences of that letter. Then, the string thus obtained is further encrypted by reversing it. INPUT OPUPUT EXPLANATION:- Example 1: Input: s = "aabc" Output: 1c1b2a Explanation: aabc Step1: a2b1c1 Step2: 1c1b2a code;- // { Driver Code Starts #include<bits/stdc++.h> using namespace std;  // } Driver Code Ends class Solution{     public:     string reverse(string s){         int i=0;         int j=s.length()-1;         while(i<j){             swap(s[i++], s[j--]);         }         return s;     }     string encryptString(string s){       int i=0;       int n