This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| int findUnion(vector<int> arr1, vector<int> arr2) { | |
| unordered_set<int> s; | |
| for (int i = 0; i < arr1.size(); i++) | |
| s.insert(arr1[i]); | |
| for (int i = 0; i < arr2.size(); i++) | |
| s.insert(arr2[i]); | |
| return s.size(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution{ | |
| public: | |
| void segregateElements(int arr[],int n) | |
| { | |
| vector<int> vp; | |
| vector <int> vn; | |
| for(int i =0;i<n;i++){ | |
| if(arr[i]>0){ | |
| vp.push_back(arr[i]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| int getSecondLargest(vector<int> &arr) { | |
| int largest =arr[0]; | |
| int slargest=-1; | |
| for(int i=1;i<arr.size();i++){ | |
| if(largest<arr[i]){ | |
| slargest =largest; | |
| largest =arr[i]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| long long gcd(long long a , long long b) | |
| { | |
| if(a == 0) | |
| return b; | |
| return gcd(b%a, a); | |
| } | |
| vector<long long> lcmAndGcd(long long A , long long B) { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // User function template for C++ | |
| class Solution { | |
| public: | |
| // Function returns the second | |
| // largest elements | |
| int getSecondLargest(vector<int> &arr) { | |
| // Code Here | |
| int largest =arr[0]; | |
| int slargest=-1; | |
| for(int i=1;i<arr.size();i++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| void solve(vector<int>& arr,int i ,int e){ | |
| if(i>=e){ | |
| return; | |
| } | |
| swap(arr[i],arr[e]); | |
| solve(arr,i+1,e-1); | |
| } | |
| void reverseArray(vector<int> &arr) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution{ | |
| public: | |
| int evenlyDivides(int N){ | |
| //code here | |
| int count=0; | |
| int temp=N; | |
| while(temp){ | |
| int t=temp%10; | |
| if(t) | |
| if(N%t==0)count++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<bits/stdc++.h> | |
| using namespace std; | |
| int solve(int n){ | |
| int sum=0; | |
| while(n--){ | |
| sum=sum*10+9; | |
| } | |
| return sum; | |
| } | |
| int main(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution | |
| { | |
| public: | |
| long long int reverse_digit(long long int n) | |
| { | |
| // Code here | |
| long long int ans=0; | |
| while(n){ | |
| int temp=n%10; | |
| ans=(ans*10)+temp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| int chocolates(int n, vector<int> &arr) { | |
| // code here | |
| int i =*min_element(arr.begin(),arr.end()); | |
| // while() | |
| return i; | |
| } | |
| }; |
NewerOlder