Samsung Interview Question for Software Developers


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    int i,i1,j,j1,k,len,length,flag=0,count=0;
    string str;
    cin>>str;
    length=str.length();
    
    for(len=1;len<length && flag==0 ; len++)
    {
        for(i=0;i<length-len;i++)
        {
            i1=i;
            for(j=i+len;j<length-len;j++)
            {
                j1=j;
                for(k=0;k<len;k++)
                {
                    if(str[i1]!=str[j1])
                    {
                        break;
                        
                    }
                    i1++;
                    j1++;
                }
                if(i1==i+len && j1==j+len)
                {
                    flag=1;
                    count++;
                }
            }
        }
    }
    cout<<len<<" "<<count<<endl;
    return 0;
}

- Sakshi Agrawal March 01, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    int i,i1,j,j1,k,len,length,flag=0,count=0;
    string str;
    cin>>str;
    length=str.length();
    
    for(len=1;len<length && flag==0 ; len++)
    {
        for(i=0;i<length-len;i++)
        {
            i1=i;
            for(j=i+len;j<length-len;j++)
            {
                j1=j;
                for(k=0;k<len;k++)
                {
                    if(str[i1]!=str[j1])
                    {
                        break;
                        
                    }
                    i1++;
                    j1++;
                }
                if(i1==i+len && j1==j+len)
                {
                    flag=1;
                    count++;
                }
            }
        }
    }
    cout<<len<<" "<<count<<endl;
    return 0;
}

- Sakshi Agrawal March 01, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    int i,i1,j,j1,k,len,length,flag=0,count=0;
    string str;
    cin>>str;
    length=str.length();
    
    for(len=1;len<length && flag==0 ; len++)
    {
        for(i=0;i<length-len;i++)
        {
            i1=i;
            for(j=i+len;j<length-len;j++)
            {
                j1=j;
                for(k=0;k<len;k++)
                {
                    if(str[i1]!=str[j1])
                    {
                        break;
                        
                    }
                    i1++;
                    j1++;
                }
                if(i1==i+len && j1==j+len)
                {
                    flag=1;
                    count++;
                }
            }
        }
    }
    cout<<len<<" "<<count<<endl;
    return 0;
}

- Sakshi March 01, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<bits/stdc++.h>
using namespace std;

int main(){
string s;
cin>>s;
int count=1;
unordered_map<string,int>mymap;
vector<int>k;
for(unsigned int i=0;i<s.length();i++){
for(unsigned int j=i;j<s.length();j++){
string temp=s.substr(i,j-i+1);

if(mymap.find(temp)!=mymap.end()){
k.push_back(temp.size());

}
else{
mymap[temp]=1;
}




}
}

sort(k.begin(),k.end());
int i=0;
while(i<k.size()&&count==k[i]){
i++;
count++;
}
cout<<count<<" "<<s.length()-count+1<<"\n";
return 0;
}

- Alkentra September 03, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<bits/stdc++.h>
using namespace std;

int main(){
    string s;
     cin>>s;
      int count=1;
  unordered_map<string,int>mymap;
  vector<int>k;  
   for(unsigned int i=0;i<s.length();i++){
     for(unsigned int j=i;j<s.length();j++){
           string temp=s.substr(i,j-i+1);
         
            if(mymap.find(temp)!=mymap.end()){
               k.push_back(temp.size()); 
                
                }
           else{
               mymap[temp]=1;
               }
         
         
         
         
         }
       }     
        
        sort(k.begin(),k.end());
        int i=0;
        while(i<k.size()&&count==k[i]){
            i++;
            count++;
            }
        cout<<count<<" "<<s.length()-count+1<<"\n";
        return 0;
    }

- Alkentra September 03, 2020 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More