## Yatra.com Interview Question Software Engineer / Developers

Country: India
Interview Type: In-Person

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

Here is a sample program using five states

``````#include<stdio.h>

enum state
{
STATE_NONE,
STATE_ODDA,
STATE_EVENA,
STATE_ODDB,
STATE_EVENB
}s;

int
dfa(const char*str)
{
enum state ssa=STATE_NONE;
enum state ssb=STATE_NONE;

int i=0;
while(str[i]!= '\0')
{
if(str[i] == 'a')
{
if(ssa == STATE_NONE)
{
ssa = STATE_ODDA;
}
else if(ssa == STATE_EVENA)
{
ssa= STATE_ODDA;
}
else
{
ssa= STATE_EVENA;
}
}
if(str[i] == 'b')
{
if(ssb == STATE_NONE)
{
ssb = STATE_ODDB;
}
else if(ssb == STATE_EVENB)
{
ssb = STATE_ODDB;
}
else
{
ssb = STATE_EVENB;
}
}
i++;
}

if(ssa == STATE_EVENA && ssb == STATE_ODDB)
{
return 1;
}

return 0;
}

int
main()
{
int i=0;
const char *str = "babababaabaabab";

if(dfa(str))
{
printf("Passed dfa\n");
}
else
{
printf("Not passed\n");
}
return 0;
}``````

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

Your program may work (haven't tried it) but, we're asked to draw a DFA, and, you have separate sets of states for As and Bs. In a DFA, all information must be combined into a single state; ie you'd have to have nodes for oddA_oddB, oddA_evenB, evenA_oddB, and evenA_evenB (plus start of course, evenA_oddB is an accepting state).

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

Name of the states is marked with two letters wich represents a and b status (Even, Odd)

imageshack.us/photo/my-images/819/automatzacarear.png/

Name:

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

### Books

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

### 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.