## krishna

BAN USERchar CurrChar = str[0];

int CurrCount = 0, i, j = 0;

char OutStr[100];

for (i = 0; CurrChar != 0,i < strlen(str); i++)

{

if(CurrChar == str[i]) CurrCount++;

else{

j = InttoStr(CurrCount, OutStr, j);

OutStr[j++] = '{';

OutStr[j++] = CurrChar;

Outstr[j++] = '}';

CurrChar = str[i];

CharCount = 1;

}

}

Ans: 2n-3

justification :

we have n points so between every adjacent points we can draw a chord (n chords).

now select any one point form n points nc1 and we can draw n-1 chords to other n-1 points but the two nodes adjacent to that point are already counted so total chords = n-3(n-1 - 2)

total number of chords = n + n-3 = 2n - 3

Ans: 2n-3

justification :

we have n points so between every adjacent points we can draw a chord (n chords).

now select any one point form n points nc1 and we can draw n-1 chords to other n-1 points but the two nodes adjacent to that point are already counted so total chords = n-3(n-1 - 2)

total number of chords = n + n-3 = 2n - 3

Form the above two notes:

we can formulate the following algorithm.

(a)Sort the dictionary with respect to first character and assign ranks for each character(which ever comes first will get lowest rank).

for each pair

(b) if Rank[c1] < Rank [c2] place an edge from c2 to c1.

(c) Now we have strings sorted by each character, with in each group of strings, proceed forward character and if str1[i] comes before str2[i] then place a directed edge in the graph from str2[i] - > str1[i].

(d) perform topological sort on the graph.

I know this is a very inefficient algorithm, i would appreciate if some one improves this.

Thanks,

Teja.

Here is my idea:

(a)start looking at the last tow digits of the year and the two digits of the month.

(b)Keep incrementing month till it reaches 12 mean while compare if they form a palindrome when we append them together.

(c)if the month exceeds 12 bring it back to 01 and increment the year by one.

(d)we can skip some of the years [2013 2019].

your comments are most appreciated.

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Please consider this approach and improve on it if possible.

- krishna February 06, 2015(a) let total number of seats occupied be x;

(b) find the window of x such that in the given arrangement number of seats occupied are maximum.

(c) fill the remaining seats by doing the following -> start from 0 to i and if there are any seats occupied move it to first available seat in the window. do the same when we pass from n - 1to i+k, fill the first available seat from right in the window.