Re: [algogeeks] Re: Repeated values

2012-11-06 Thread Saurabh Kumar
yes, that was an implementation mistake but what I meant to say was- Adding extra check of indirect xor'ing could have a pitfall too. Try the case: [0 1 1 1 4 4] http://ideone.com/3sreLZ On 4 November 2012 10:13, Vikram Pradhan vpradha...@gmail.com wrote: It should have caught in the first

Re: [algogeeks] Ternary operators

2012-11-02 Thread Saurabh Kumar
if we have 1 in case of 0? On Thu, Nov 1, 2012 at 5:20 PM, Saurabh Kumar srbh.ku...@gmail.comwrote: There's nothing to do with the type of A String. The reason for which the first code gives compilation error is: operator () has higher precedence than ternary operator (?:) so, without braces

Re: [algogeeks] what to modify in given code so that dublicate permutations should not come

2012-11-01 Thread Saurabh Kumar
You'd simply have to keep track of : has particular alphabet already been used or not. You can do this by maintaining a 'used' array of 0/1 . Set and unset the respective index before and after the recursion. Here's the modified code: #includestdio.h #includestring.h #includemalloc.h *void

Re: [algogeeks] Ternary operators

2012-11-01 Thread Saurabh Kumar
There's nothing to do with the type of A String. The reason for which the first code gives compilation error is: operator () has higher precedence than ternary operator (?:) so, without braces your are actually messing up the parsing of coutstream. * cout test ? A String : 0 endl;*

Re: [algogeeks] Pre/Post L and r value

2012-11-01 Thread Saurabh Kumar
increment also..it will help a lot..i can guess it will do n++ and return itself..plz give code snippet... On Mon, Oct 29, 2012 at 10:50 AM, Saurabh Kumar srbh.ku...@gmail.comwrote: Post increment returns temp object because it has to return the old value of object not the new incremented one

Re: [algogeeks] Re: Repeated values

2012-11-01 Thread Saurabh Kumar
@Vikram - your approach fails for [4 1 1 1 1] On 1 November 2012 00:09, Vikram Pradhan vpradha...@gmail.com wrote: @Don It will be an infinite loop for some cases ...like try this i=1, and a[1] = 5 , a[5] = 5 *Solution:* As the numbers are from 0 to N-1 so we can xor the value with its

Re: [algogeeks] Pre/Post L and r value

2012-10-30 Thread Saurabh Kumar
in an exprression, as you would be assigning nowhere. On 27 October 2012 20:09, rahul sharma rahul23111...@gmail.com wrote: But y post returns temp. object On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar srbh.ku...@gmail.comwrote: i++: Post increment can't be a lvalue because Post increment

Re: [algogeeks] C Function Pointer(Typedef)

2012-10-30 Thread Saurabh Kumar
because, pFunc is just a typedef. you'd have to instantiate a variable at least in order to call your function. like - typedef int (*pFunc) (int); pFunc fptr = func; //fptr is now a variable on stack which points to your function. fptr(5); // call that function. On 30 October 2012 01:41, rahul

Re: [algogeeks] INTERVIEW QUESTION

2012-10-30 Thread Saurabh Kumar
stands for?how are the values allocated to it ? should it be for each wrong word not mentioned in the dictionary we got to check if the word exists with edit distance equal to 1 in dictioanry and so on until we get the correct word??? on Sat, Oct 27, 2012 at 8:12 AM, Saurabh Kumar srbh.ku

Re: [algogeeks] Sequence Point C with postincremented

2012-10-27 Thread Saurabh Kumar
You're right , || all introduce a sequence point. In first case evaluation proceeds like this: j = (i++, i++); *i++* Post increment the i (i is now 11) *j = i++* Post increment the i (j is assigned 11 and i is now 12) In second case, the whole of rvalue for = operator will be evaluated

Re: [algogeeks] INTERVIEW QUESTION

2012-10-27 Thread Saurabh Kumar
could you please share the link? coz at first glance a Trie looks like a bad choice for this task. I'd go with the Levenshtein distance and a kd-tree. First implement the Levenshtein distance algorithm to calculate the edit distance of two strings. Second, since Levenshtein distance qualifies as

Re: [algogeeks] Finite state automata accpt string of length 6

2012-10-27 Thread Saurabh Kumar
20 seems correct. You can also view this as all permutations of xyzabc such that the ordering xyz and abc should appear as is. On 27 October 2012 05:57, payal gupta gpt.pa...@gmail.com wrote: should be 6C3 or 20 perhaps. On Sat, Oct 27, 2012 at 3:29 AM, rahul sharma

Re: [algogeeks] Pre/Post L and r value

2012-10-27 Thread Saurabh Kumar
i++: Post increment can't be a lvalue because Post increment internally returns a temporary object (NOT the location of i) hence you cannot assign anything to it. The result of i++ can be used only as a rvalue. ++i: whereas, in Pre-increment value gets incremented and the same location is

Re: [algogeeks] Finite state automata accpt string of length 6

2012-10-27 Thread Saurabh Kumar
Since this is a small grid you can count it manually but in general problem is to count no. of paths from bottom-left corner to top-right corner (provided all the transition alphabets in the automata are distinct in the respective dimensions e.g. here, xyz in one dimension and abc in other) You

Re: [algogeeks] INTERVIEW QUESTION

2012-10-27 Thread Saurabh Kumar
Firstly, that question is missing a lot of details. In absence of those details I'm going to make soem assumptions: 1. cube is odd lengthed, so that we can define a unique center of cube. 2. While traversing from a cell(x, y, z) we can only move into any of the 6 adjacent cells[x(+-)1, y(+-)1,

Re: [algogeeks] Re: Random Number generation

2012-10-27 Thread Saurabh Kumar
, Saurabh Kumar srbh.ku...@gmail.com wrote: Take a look at Linear Congruential Generatorhttp://en.wikipedia.org/wiki/Linear_congruential_generator algorithm for generating pseudo random numbers. On 25 October 2012 16:58, bharat b bagana.bharatku...@gmail.com wrote: I heard

Re: [algogeeks] Random Number generation

2012-10-25 Thread Saurabh Kumar
Take a look at Linear Congruential Generatorhttp://en.wikipedia.org/wiki/Linear_congruential_generator algorithm for generating pseudo random numbers. On 25 October 2012 16:58, bharat b bagana.bharatku...@gmail.com wrote: I heard that LINUX uses our past time mouse movement and keys pressed at

Re: [algogeeks] Re: c code help!!!!

2012-10-21 Thread Saurabh Kumar
Sorry, about that. Read it as: Yes a hex digit is represented by 4 bits but 1 Byte is being read using a char pointer* and you're printing the values in those Bytes. On 21 October 2012 01:03, Saurabh Kumar srbh.ku...@gmail.com wrote: Sorry, I don't understand your question. *%.2x *is only

Re: [algogeeks] Re: c code help!!!!

2012-10-21 Thread Saurabh Kumar
Sorry, I don't understand your question. *%.2x *is only a precision specifier still. (%.2x was used for neat formatting only, because you are printing the values only 1 Byte long and a Byte can occupy at max 2digits in hex) hex representated by 4 bits. Yes hex is represented by 4 bits i.e. 1 Byte

Re: [algogeeks] test cases

2012-10-21 Thread Saurabh Kumar
, Saurabh Kumar srbh.ku...@gmail.comwrote: Actually *fflush(stdin)* is the problem here, your reading of inputs is all messed up, at least on my machine( and probably on the machine you are submitting the code too). Maybe it's working fine on your particular environment but generally fflush

Re: [algogeeks] permutations using stack

2012-10-21 Thread Saurabh Kumar
answer is right there in the strings: S = PPXXPXPXPPX... Possible permutations = No. of ways to generate strings of P/X's such that in each sub-string S[0..i] no. of P's is always greater than or equal to no. of X's. You can also view this as - all possible strings of n balanced parentheses.

Re: [algogeeks] c code help!!!!

2012-10-20 Thread Saurabh Kumar
It only means - If address in hexadecimal is less than 2 digits, it will add extra padding 0's. If it's more than 2 digits it will simply print the address as is. i.e. suppose If address is *E* it will print: *0E* (padding an extra zero) that's all. On 21 October 2012 00:05, rahul sharma

Re: [algogeeks] test cases

2012-10-18 Thread Saurabh Kumar
is failing only for a particular test case .can you plz suggest any such test case. On Thu, Oct 18, 2012 at 6:08 PM, w.s miller wentworth.miller6...@gmail.com wrote: @Saurabh kumar But i have used fflush(stdin),which flushes the standard input fille. So there is nothing in stdin when i go to read

Re: [algogeeks] this pointer help c++

2012-10-10 Thread Saurabh Kumar
to return pointer(this).. int * fun()//return pointer to int then what does return by reference mean if i return ( *this)..then what actually returns...full object???or pointer to object...mix questions ...plz clear me.. On Tue, Oct 9, 2012 at 11:26 PM, Saurabh Kumar

Re: [algogeeks] Virtual functions in constructor

2012-10-10 Thread Saurabh Kumar
In short: Call for virtual function in constructor is redirected to the local function because, the derived part of the object has not being initialized yet(remember you are still in Bases' constructor) and it makes no sense to call a derived's implementation of a virtual function, which in turn

Re: [algogeeks] Min Edges to be added to DAG to make it Strongly connected?

2012-10-09 Thread Saurabh Kumar
We are attempting for DAGs only. Your graph is not acyclic. :) On 9 October 2012 21:57, Jaspreet Singh jassajjassaj...@gmail.com wrote: What if this :- a-»b ^--' c here max of both is 1 but ans is 2. On Oct 8, 2012 11:38 PM, Saurabh Kumar srbh.ku...@gmail.com wrote: You'd need: max

Re: [algogeeks] this pointer help c++

2012-10-09 Thread Saurabh Kumar
as we know reference is a const pointer That is Not quite true. our aim is ony to return pointer to circle No. our aim is to return a reference to circle. When you've to define a reference you do something like: *Circle ref = c;* you *don't* do: *Circle ref = c;* Right ? Same is the case

Re: [algogeeks] Min Edges to be added to DAG to make it Strongly connected?

2012-10-08 Thread Saurabh Kumar
You'd need: max(#vertices-with-0in-degree, #vertices-with-0out-degree) edges at least. On 8 October 2012 20:20, bharat b bagana.bharatku...@gmail.com wrote: @jaspreet: take an ex: B-A B-C B-D Here the no.of zero-indegree is one . But its not the correct ans. On Mon, Oct 8, 2012 at 1:19

Re: [algogeeks] Nested Function C

2012-10-03 Thread Saurabh Kumar
It's compiler dependent. gcc comes from GNU project. ANSI C doesn't allow nested function definitions. On 3 October 2012 01:06, rahul sharma rahul23111...@gmail.com wrote: Guys i have read that we cant define function in another function in c Then why this followung program running fine on gcc

Re: [algogeeks] LOGIC!!!

2012-08-30 Thread Saurabh Kumar
I think, if the Graph is 2-colorable (i.e. Bipartite) trip can be arranged. On 30 August 2012 09:43, ashish mann ashishman...@gmail.com wrote: Q. A company organizes two foreign trips for its employees yearly. Aim of the trip is to increase interaction among the employees of the company and