• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Password Predictor

October 9, 2014 by Dhaval Dave

Danny has a possible list of passwords of Manny’s facebook account. All passwords length is odd. But Danny knows that Manny is a big fan of palindromes. So, his password and reverse of his password both should be in the list.
You have to print the length of Manny’s password and it’s middle character.
Note : The solution will be unique.

INPUT
The first line of input contains the integer N, the number of possible passwords.
Each of the following N lines contains a single word, its length being an odd number greater than 2 and lesser than 14. All characters are lowercase letters of the English alphabet.

OUTPUT
The first and only line of output must contain the length of the correct password and its central letter.

CONSTRAINTS
1 < = N <= 100

Sample Input
4
abc
def
feg
cba

Sample Output
3 b

Logic :

Store each password and its reverse in hash function.
for each password search weather its reverse is existing in hash or not.

If yes, return length+middle element of it.
else continue.

#include <stdio.h>
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;
#define MAX 100
string reverse(string temp){
    //cout<<” In function “<<temp;
    char pwd[temp.length()];
    int j=0;
    for(int i=(temp.length())-1;i>=0;i–,j++){
        pwd[j]=temp[i];
    }
    pwd[j]=’’;
    string str(pwd);
    return str;
}
int findPassword(string password[],int k){
    string temp;
    char *op;
    unordered_map<string, string> ht;
    for(int i=0;i<k;i++){
        if(password[i].length()%2 == 0 ) {cout<<“error in length” ; return 0 ;}    
        temp=password[i];
        ht.insert(make_pair(temp,reverse(temp)));
        if(ht.find(reverse(temp))!=ht.end()){
            //cout<<temp<< “<=>” <<reverse(temp)<<endl ;
            cout<<password[i].length()<<” “<<temp[(password[i].length())/2];
            return 1;
        }//if
    }//for
    return 0;
}
int main(){

    string password[MAX];
    unordered_map<string, string> ht;

    int i=0, j=0, k=0, t=0;
    cin>>t;
    k=t;
    while(t){
        cin>>password[i];
        –t; ++i;
    }
    findPassword(password,k);

}//main

see working code here : http://ideone.com/WqbO5v

Новости видео

Similar Articles

Filed Under: Adobe Interview Questions, Amazon Interview Question, Hacker Earth Questions, Interview Questions, problem Tagged With: string

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

There are N nuts and N bolts, u have to find all the pairs of nuts and bolts in minimum no. of iteration

Find next greater number with same set of digits

Flipkart Set 1 On Campus with Answers

Longest Increasing Subsequence

N Petrol bunks or City arranged in circle. You have Fuel and distance between petrol bunks. Is it possible to find starting point so that we can travel all Petrol Bunks

Maximum sum contiguous subarray of an Array

Facebook Interview Question : Interleave List

Find an index i such that Arr [i] = i in array of n distinct integers sorted in ascending order.

Common Ancestor in a Binary Tree or Binary Search Tree

Add Sub Multiply very large number stored as string

Inorder and Preorder traversals of a Binary Tree given. Output the Postorder traversal of it.

Python String and numbers

The Magic HackerEarth Nirvana solutions Hiring Challenge

write a c program that given a set a of n numbers and another number x determines whether or not there exist two elements in s whose sum is exactly x

SAP Interview Questions

25 horses 5 tracks Find 3 fastest puzzle

Amazon Interview On-Campus For Internship – 1

SAP Hiring Off-Campus General Aptitude

Wrong Directions given find minimum moves so that he can reach to the destination

Given Set of words or A String find whether chain is possible from these words or not

BlueStone E-commerce Interview Experience

Possible sizes of bus to carry n groups of friends

Maximum of all subarrays of size k

Memory Efficient LinkedList

Urban Ladder Written Test.

Given a float number convert it into the string WITHOUT using any inbuilt Function

BFS (Breath First Search)

robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

How strtok() Works

Client Server C program

Copyright © 2025 · Genesis Framework · WordPress · Log in