Re: [algogeeks] C output

2012-10-17 Thread Vikas Kumar
gthOfString +1 ( +1 for '\0') strlen(anyString) = simple length sizeof(anyArray) = numberofElementPresentInArray*sizeof(dataType) -- *Thanks,* *Vikas Kumar* * * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group

[algogeeks] Re: coding round question

2011-10-30 Thread vikas kumar
The question was from startup company verego (may be misspelled), you understood it in correct way. We are given 'k' number of ranges in the fashion L, R they are all integers in big ranges , (assume long long for the case) then we are given move operation defined as move( i, +1/-1) : so range

[algogeeks] coding round question

2011-10-30 Thread vikas kumar
There are a number of integer ranges say [ L, R]i denoting left and right of segment i, lets says we are given K such segments and we define one operation as move which makes our chosen segment to move either +1 or -1 so after move(i, +1) segment i will be [L+1, R+1]. There are some particular num

[algogeeks] Re: C Question

2011-06-11 Thread vikas kumar
x is a pointer which can be changed from out side and stores the pointers for int* On Jun 8, 10:58 am, Vishal Thanki wrote: > Following declaration makes the "x" as a volatile pointer to an integer. > > int *volatile x; > > But what does following means? > > int **volatile x; > > ~Vishal -- You

Re: [algogeeks] Re: intel puzzle

2011-02-24 Thread Vikas Kumar
@priyaranjan No,Your triangle will be right angle triangle. In fact any triangle chosen will be right angle triangle. Proof: suppose there are 2 planes kept at parallel with each other.(top bottom) join corresponding vertices of up to down and form cube. Now 3 points chosen can be on same plan

Re: [algogeeks] Maths

2011-02-16 Thread Vikas Kumar
f(n)=n-1. On Wed, Feb 16, 2011 at 7:39 PM, Akshata Sharma wrote: > please help.. > > if f(n+1) = max{ f(k) + f(n-k+1) + 1} for 1 <= k <= n; f(1) = 0. > Find f(n+1) in terms of n. > Eg: f(4) = ? n = 3; 1<= k <= 3; f(4) = max{f(1) + f(3) + 1, f(2) + > f(2)+1, f(3) + f(1) +1} > > -- > You received

Re: [algogeeks] Maximize the Time to see TV

2011-02-01 Thread Vikas Kumar
@Snehal just a hint: there is no need of that channel 1 & channel 2. just treat each program as independent program. On Mon, Jan 31, 2011 at 10:44 PM, snehal jain wrote: > or provide some link > > > On Mon, Jan 31, 2011 at 10:44 PM, snehal jain wrote: > >> @ juver++ >> >> can you please share

[algogeeks] Re: ReVerse a string using recursion

2010-09-24 Thread vikas kumar
use it like this char* strrev(char *) strrev(str) void strrev(char *str) { xstrrev(str , 0, strlen(str)); // code posted by Nishant } :-) On Sep 23, 11:35 pm, albert theboss wrote: > Ur function prototype is not similar to one i posted before > > check it out -- You rece

[algogeeks] Re: Unbounded dictionary lookup

2010-09-22 Thread vikas kumar
we can approach it like *lets start with index 0 if (found) return index else index += INCR_; *we will try to increment with INCR_ until one of the following conditions met index goes out of bounds found the words which must come after the value eg "meet" should occur prior to "must" found

[algogeeks] Re: ind out which row has the maximum number of 1's in 2D array

2010-09-22 Thread vikas kumar
int getMaxOneRow() { ...int maxOne = 0, maxRow = 0; ...for (curRow=0; curRow maxOne) ..{ .maxOne = n; .maxRow = curRow; ..} ...} return maxRow; } int getOneCount(int row) { ...int count =0; ...for(int i =0; i wrote: > There is a 2 dimensional array with each cell containin

[algogeeks] Re: Inserting a box with lesser dimension into a box of bigger dimensions than that.

2010-09-22 Thread vikas kumar
you can search for box stacking problem in google. There is a DP method. On Sep 22, 12:11 am, Dave wrote: > Certainly having a smaller volume is necessary for a box to fit in > another box, but it is not sufficient. E.g., a box of size 1 x 1 x 1 > will not fit in a box of size 2 x 2 x 1/2. > > Da

[algogeeks] Re: number of inversion pairs

2010-09-20 Thread vikas kumar
use a bst and insert in it reverse of array. use a count in bst node and incr count at each right child insertion On Sep 14, 11:00 am, "Shiv ..." wrote: > A pseudo code- > >   int n; //= number of inputs. >   cin>>*a; // the inputs. > >   int ** invArr; >   *inVArr[n-1] = NULL; >   //ini

[algogeeks] Re: Google Interview Question-Snake and Ladder Design

2010-09-17 Thread vikas kumar
take this approach fill array of snakes starting position in snake[num_snake] for each snake[i] , take the end of snake and fill in some other array take random number gen and fill these arrays--> e.g. end_snake[i] = ran(start_snake[i]-10) // so that snake does not end up in same row same logic

[algogeeks] Re: Drawing a graph

2010-09-17 Thread vikas kumar
use opengl library to draw the graph or whatever. take RED BOOK for reference. On Sep 14, 5:54 pm, Mithun wrote: > Can anyone help me with the code for drawing a graph in C or CPP > (using graphics) > > Input is an Adjacency matrix -- You received this message because you are subscribed to the

[algogeeks] Re: Amazon Question

2010-09-17 Thread vikas kumar
struct list { median --> median from the start to num number --->number list *next }; during insertion : insert in sorted LL after that all subseq node's median has to be modified O(n) during median_retriev check the median value and return that O(1) I assumed deletion is not happening.

[algogeeks] Re: Yahoo Question

2010-09-17 Thread vikas kumar
@Bittu I am confused about one point you need to process atleast n*k elements so how will you do it in nlogk time. It seems really tricky if possible.it's min time should be O(nk). correct me if I am wrong. On Sep 17, 6:34 am, tkcn wrote: > Use k-way merging +1. > > 1. Before the merg

[algogeeks] Re: Google Interview Question

2010-09-17 Thread vikas kumar
nice recurrence On Sep 14, 9:29 pm, Gene wrote: > You can approach this the same way you'd do it by hand.  Build up the > string of brackets left to right.  For each position, you have a > decision of either ( or ) bracket except for two constraints: > (1) if you've already decided to use

[algogeeks] Re: Amazon intern Question

2010-09-04 Thread vikas kumar
I think Gene is right. they are asking more than search here. Thanks to Gene for suggesting this idea :) now the how part, we can have a level of abstraction: no of products matching to name ---> use trie, suffix tree, some genetic algo, string matching, ms tree.. based on products ge

Re: [algogeeks] Re: Subsequence

2010-08-25 Thread Vikas Kumar
can you define what here subsequence means? On Wed, Aug 25, 2010 at 9:32 PM, Rahul wrote: > @Jaswanth > It will be really kind if you will state the algorithm rather than > providing codes, as it is tedious. > > -- > You received this message because you are subscribed to the Google Groups > "Al

[algogeeks] Re: Linked List

2010-08-19 Thread vikas kumar
you are right in the way in cpp code it is not required but in C , you can not write like node * start. it only recognise new type when typedef is applied. second one is already explained by vijay On Aug 18, 6:16 pm, Vijay wrote: > 1. typedef is used to rename the data type. Here struct node is a

[algogeeks] Re: how to implement TAIL command of unix.

2010-08-16 Thread vikas kumar
the method of farword seek is inefficient. consider case of 10 lines and you want to display only 3-4 lines. better seek from end. use a buffer[buf_size]. let size =filesize. lc = 0; while(lc <= given line input) { fseek(fp, size); if(size < buf_size) fread(fp, size, buffer); else fread(f

[algogeeks] Re: Dynamic Programming Problem on Strings

2010-08-13 Thread vikas kumar
what about printing these strings onto terminal. can printing of the string is also similar. I tried to develop the algo but got messed up.can some one help? On Aug 8, 2:53 am, Amir hossein Shahriari wrote: > @ankur: dp[i][j] number of (prefix) strings that have i As and j Bs is: > dp[i-1][j] num

[algogeeks] Re: interesting c++ questions

2010-08-04 Thread vikas kumar
1) Yes ofcourse 2) yes you can 3) yes ofcourse 4) yes 5) i dont think . May we our default constructor def not matching ;) On Aug 3, 8:42 pm, Raj N wrote: > 1) Can a constructor call another constructor to initialize the same > object? > 2) Can a struct variable be assigned to another if the stru

[algogeeks] Re: Amazon Placement Question

2010-08-04 Thread vikas kumar
@ Ashish: make a balanced binary tree of depth >3 and try the approach, u need to save the pointers somewhere if they are in different subtrees and at same level. Stack will be most appropriate one to use for this purpose. On Aug 2, 7:34 pm, Ashish Goel wrote: > why stack? that is DFS > > it w

[algogeeks] Re: Amazon Placement Question

2010-08-02 Thread vikas kumar
driver(Tree *root) { node *array = malloc(sizeof(node *) *H ); /* take the height node pointer array. this will act as source pointer of each list */ makeList(root, 0, array) } makeList(Tree *root, int level, node *array) { if(! root) return ; /*do a Depth traversal and store the list

[algogeeks] Re: number of BST's

2010-07-31 Thread vikas kumar
int countTree(int num) { if(num <= 1) return 1; int sum =0; for(i =1; i wrote: > Follow up on Catalon Nubmer... > > On Fri, Jul 30, 2010 at 10:44 AM, Amit Jaspal wrote: > > > > > n is clearly a number lets say 3 then BST's with 1,2,3 values as key are to > > be calculated > > > On Fri, Jul

[algogeeks] Re: Merging of Binary trees

2010-07-27 Thread vikas kumar
if it is a simple BT then you can simply attach the root to either child ( which is null ) of other tree . just simply go leftmost and then assign root of other tree as left child, as suggested by Gene. On Jul 27, 8:23 am, Gene wrote: > You actually only need a singly linked list.  See and old di

[algogeeks] Re: Merging of Binary trees

2010-07-26 Thread vikas kumar
are you asking for BST or simple BT. what are the conditions you want to follow if simple BT On Jul 26, 12:59 am, AlgoBoy wrote: > Does anyone know how to merge two binary trees in O(n logn logn) > complexity.. > intiutive solution is to flatten both the trees (by inorder > traversal ) and then c

[algogeeks] Re: Difference b/w two elements in a array

2010-07-14 Thread vikas kumar
Thanks Amit and srikanth for pointing that out. I should have done some analysis before posting this solution. we can do this problem in 2 steps: find-min-diff(arr a) { sort(a) find(a, 0, min=INF, i=0, j=0) return {min, i, j} } find(a, index, min, i, j) { if(a[index+1] - a[index] < mi

[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread vikas kumar
I did not get your point. for 2 6 3 7 min 2 sec min 3 difference is 1 answer is 2 and 3 what more is asked?? On Jul 12, 2:21 pm, srikanth sg wrote: > 2 6 3  7 > check for this > > On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar wrote: > > > traverse array with 2 elements k

[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread vikas kumar
traverse array with 2 elements keeping track of 2 min elements. time O(n) space O(1) On Jul 11, 9:34 pm, Amit Jaspal wrote: > Constraint - O(n) > > On Sun, Jul 11, 2010 at 9:24 AM, amit wrote: > > Given an array of size n.find 2 numbers from array whose difference is > > least. > > > -- > > You

[algogeeks] Re: There are 2 type of values - 1 byte and 2 byte given a pointer to any point in the string tell me if its a 1B or 2B value ending there. MSB of 1-byte character is 0 and MSB of 2-byte

2010-07-12 Thread vikas kumar
is it something different than this foo(char *p, int num) { if(!p) return "error" if(num > 0 && p[num-1] == 0) print " 2 byte value" else print "1 byte value" } On Jul 11, 11:18 pm, Tech Id wrote: > Question is not clear to me :( > Can you explain a li

[algogeeks] Re: Difference b/w two elements in a array

2010-07-12 Thread vikas kumar
traverse array with 2 elements keeping track of 2 min elements. time O(n) space O(1) On Jul 11, 9:34 pm, Amit Jaspal wrote: > Constraint - O(n) > > On Sun, Jul 11, 2010 at 9:24 AM, amit wrote: > > Given an array of size n.find 2 numbers from array whose difference is > > least. > > > -- > > You

[algogeeks] Re: Find the next number for a given number without using any arithmetic operators(use bit operations)

2010-06-25 Thread vikas kumar
adder with add value 1 On Jun 24, 8:30 pm, jaladhi dave wrote: > Another approach :http://codepad.org/CqKIZJeO > > On Thu, Jun 24, 2010 at 7:31 PM, mohit ranjan wrote: > > > @Dave > > > Can u plz explain the logic behind this.. > > > Mohit > > > On Thu, Jun 24, 2010 at 12:44 AM, Dave wrote: > >

[algogeeks] Re: Find the next number for a given number without using any arithmetic operators(use bit operations)

2010-06-25 Thread vikas kumar
adder with add value 1 On Jun 24, 8:30 pm, jaladhi dave wrote: > Another approach :http://codepad.org/CqKIZJeO > > On Thu, Jun 24, 2010 at 7:31 PM, mohit ranjan wrote: > > > @Dave > > > Can u plz explain the logic behind this.. > > > Mohit > > > On Thu, Jun 24, 2010 at 12:44 AM, Dave wrote: > >