30 Day Risk-Free Guarantee:
100% money back if you're unsatisfied.
Book (308 Pages):
  • 150 Programming Interview Questions and Solutions
  • Five Proven Approaches to Solving Tough Algorithm Questions
  • Ten Mistakes Candidates Make -- And How to Avoid Them
  • Steps to Prepare for Behavioral and Technical Questions
  • Interview War Stories: A View from the Interviewer's Side
  • Book Preview and More Info

Video (One Hour):
  • Watch CareerCup's founder perform a totally unscripted technical interview of a candidate.
  • Overview of what interviewers look for in software engineering jobs.
  • Technical questions with white-boarding coding where the candidate does well - and struggles.
  • Interviewer reviews with what went well and poorly.
  • Video Preview and More Info

Resume Review (24 - 48hr)
  • Get your resume reviewed by a trained engineering interviewer. More Info
All Products / Services


Express Prep Package (Book)
$29.99 for e-book | $32.45 for paperback
Buy E-Book Buy on Amazon


Standard Prep Package (E-Book & Video)
Emailed Instantly | $39.99
Buy Standard

Elite Prep Package (E-Book, Video & Resume)
Emailed Instantly | $99.99
Buy Elite
 



Asked in 1st and 2nd interview at campus placement at IIIT Gwalior.
An 8 x 8 char array is provided with random letters. You have to tell if a given string occurs.

eg

String to find = "computer"

Array[] = {
b b b b b b b b
b b b c b b b b
b b o b b b b b
b b b m p b t b
b b b u b u b e
b b b t b b b r
b b b e b b b b
b b b r b b b b
}

Ans : Available

13


Mohit Garg on April 20, 2008 |Edit | Edit

Interviewer expected me to write most of code(not pseudo) and take care of the special cases. Time limit upto 45-50 mins.

cMonkey on May 19, 2008 |Edit | Edit

I would use an Hash table for this problem, to initially scan the entire array into the hash, I would also track the duplicates on the hash elements , hash[x]+=1. Then I would take a string pointer in computer and go from start to finish. I will provide the code later for this problem.

The reason for using the hash is becuase in the above 8x8 array, the computer is spread in both x and y directions.

mohan.bg on June 20, 2008 |Edit | Edit

what cMonkey says is the straight solution...I would ask the interviewer is there any restrictions on time and space usages.....because hash table might take more space...

King_K on June 30, 2008 |Edit | Edit

Do a dfs on the graph...for "computer"...
I would keep a track for each character, where in the matrix it occurs in a separate table. This helps me get the start node quickly. And then DFS with +1 and -1 on rows and cols as adjacent edges.

Maybe we need to be careful of backedges...maybe not...
Example: "mum" can be found by going from m to u and then back to "m". Will check if thats valid...

@king_k! on July 02, 2008 |Edit | Edit

what do u mean ??
how do u build a graph for "computer" ? and y a graph?

vodangkhoa on July 03, 2008 |Edit | Edit

boolean containWord(Board board, String result, final String TOFIND){

if (result.equals(TOFIND)){
return true;
} else {
foreach (Char char: board){
foreach (Char c: getNeighbors(char))
boolean result = containWord(board, result + c) || containWord(board, result);
if (result){
return true;
}
}
}
return false;
}

VladD on July 13, 2008 |Edit | Edit

How about sorting array and the input word ("computer") and then set two pointers to the beggining of each and iterate till the end of either of them. If we are at the end of "computer" means we found the match otherwise we didn't?

XYZ on September 04, 2008 |Edit | Edit

set<char> word="computer";
....for (int i=0; i<m*n; i++){
.......if (!word.size()){
...........found=true;
...........break;
.......}
.......}else
...........word.erase(matrix[i/m][i%m]);
.......}

NL on October 04, 2008 |Edit | Edit

2 stacks

Anonymous on October 09, 2008 |Edit | Edit

what 2 stacks?

rajnesh on October 10, 2008 |Edit | Edit

please give exact solution

rajnesh on October 10, 2008 |Edit | Edit

how we use 2 stack

Pratharth on February 09, 2009 |Edit | Edit

Why do we need a hashtable. We can just do it using an int array of size 256 since the array doesn't have any unicode chars.

Add a Text Comment | Add Runnable Code
Name:
Comment:

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








Amazon (1033)Bloomberg LP (403)Qualcomm (117)Adobe (88)Goldman Sachs (78)NetApp (49)IBM (43)Morgan Stanley (33)CapitalIQ (30)Sophos (25)Achieve Internet (23)Electronic Arts (19)Motorola (18)Research In Motion (17)Flipkart (16)
Microsoft (867)Google (141)NVIDIA (98)Yahoo (82)Epic Systems (69)Expedia (47)VMWare Inc (43)Apple (32)Cisco Systems (28)Facebook (23)Infosys (22)Agilent Technologies (19)Sage Software (17)Deshaw Inc (16)FlexTrade (15)
More Companies »
Software Engineer / Dev... (1062)Financial Software Deve... (170)Testing / Quality Assur... (56)Analyst (35)Virus Researcher (25)Field Sales (15)Developer Program Engin... (9)Front-end Software Engi... (6)MyJoB (5)area sales manager (4)Assistant (3)Cabin crew (2)Accountant (1)personnel (1)Intern (1)
Software Engineer in Te... (288)Program Manager (65)Development Support Eng... (47)INTERN(MSIDC) (28)Web Developer (18)System Administrator (10)Consultant (10)Production Engineer (5)Associate Technology L2 (5)AcquireKnowledge (4)Product Security Engine... (3)Solutions Architect (2)Gamer (1)mts (1)Fresh graduate interview (0)
More Job Titles »
Algorithm (1073)Terminology & Trivia (294)C (166)Object Oriented Design (159)Java (121)Testing (114)Arrays (101)Operating System (78)Database (70)Linked List (62)String Manipulation (56)Networking / Web / Inte... (44)Threads (36)Linux Kernel (33)PHP (22)
Coding (511)C++ (204)Behavioral (159)Data Structures (155)Experience (116)Brain Teasers (111)Computer Architecture &... (79)General Questions and C... (73)Trees and Graphs (69)Math & Computation (57)Application / UI Design (45)Ideas (38)System Design (35)Puzzles (30)Bit Manipulation (20)
More Topics »
CareerCup Official Interview Book Daily Questions Requests for Help Mock Interviews Video for Cracking the Coding Interview Job Placement Service CareerCup Blog
My Profile Edit Profile & Email Settings Sign Out