Given a number we have to calculate the square root of number and print the resultant value .
So what is square root of number?
Square root of a number is
Example:
input:abcdaab
output:a b
Logic:
step 1-make a hash array to count the character in a string.
step 2-iterate the whole string and increment hash array value .
step 3-iterate the array and print the value which is present more than once
Code-
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int hash[26]={0}; for(int i=0;i<s.length();i++) { hash[s[i]-'a']++; } for(int i=0;i<26;i++) { if(hash[i]>1) { cout<<char(i+'a')<<endl; } } }
Output:
a b
Time complexity:0(N)
Space Complexity:O(N)