Re: [algogeeks] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-30 Thread rahul patil
check this code . if it works correctly ? reverse the ans and you will find the no converted in target base.(ignore extra 0's) #include stdio.h #include stdlib.h #include string.h #define MAX 10 int main() { int i; int b1,b2; char no1[MAX] = ,no2[MAX] = ; int *result = (int *) calloc

[algogeeks] Converting a decimal number to base -2

2010-08-30 Thread Maria
Write some code to convert a positive integer into base minus 2. That is, whereas base 2 has a 1's place, a 2's place, a 4's place, etc., base minus 2 has a 1's place, a minus 2's place, a 4's place, a minus 8's place, ... (-2)^n. -- You received this message because you are subscribed to the

[algogeeks] Modified subset-sum problem

2010-08-30 Thread Maria
Is it possible to find a subset in an array dat produces the specified sum 'k' wen the array contains negative numbers? For ex: arr[]={1,-2,4,-8,16,-32,64} k=25; O/p:subset={1,-8,-32,64} -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Modified subset-sum problem

2010-08-30 Thread Maria
Is it possible to find a subset in an array dat produces the specified sum 'k' wen the array contains negative numbers? For ex: arr[]={1,-2,4,-8,16,-32,64} k=25; O/p:subset={1,-8,-32,64} -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] Re: Microsoft interview question

2010-08-30 Thread Abhishek Shrivastav
its an infinite loop. Beware. On Mon, Aug 23, 2010 at 5:32 AM, Gene gene.ress...@gmail.com wrote: This doesn't work on abb for example. On Aug 22, 9:28 am, Ashish Goel ashg...@gmail.com wrote: use a array arr[char]=count char represent say a-z count is # of occurances while

Re: [algogeeks] Modified subset-sum problem

2010-08-30 Thread rahul patil
yes. You can do it simply by dynamic programming. try all combination. On Mon, Aug 30, 2010 at 2:41 PM, Maria lydwin.ma...@gmail.com wrote: Is it possible to find a subset in an array dat produces the specified sum 'k' wen the array contains negative numbers? For ex:

Re: [algogeeks] Re: Binary tree to LL

2010-08-30 Thread Chonku
@albert I am not forming a separate list. My assumption was that next pointer is present in the node. But I will try to post a solution with only left and right pointers. On Mon, Aug 30, 2010 at 12:10 AM, albert theboss alberttheb...@gmail.comwrote: @Chonku: you cant use next pointer in

Re: [algogeeks] Re: Subsequence

2010-08-30 Thread Ankit Singh
Does not work with negative nos. @ Yan Wang,@Adam it worked for ur inputs. With the input like a= {10,0,0,0}, k = 2 it will give 0, 0 as output. -Code- import java.util.ArrayList; import java.util.Collections; import java.util.List; public class NondecreasingMaxsum { // With

[algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread ANKIT AGGARWAL
divide each number by -2 until you get -1, or 1 (Remembering that remainder is always +ve) Ex 1) -2 | 2 | 0 | -1 | Interpret -1 as 11 so binary is 110 2) -2 | 3 | 1 |-1| Binary : 111 3) -2 | 4| 0 |-2| 0 | 1| Binary : 110 4) -2 | 5| 1 |-2| 0 | 1| Binary : 101 5)

Re: [algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread vikash jain
can you plzz tel me y -1 is interpreted as 11 ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: Subsequence

2010-08-30 Thread vikash jain
@Yan Wang..can u tel me wat u meant by saying the following : And we know all the different numbers in A[...]. we put them in a rigorously increasing sequence B[1..p], where B[1] B[2] ... B[p-1] B[p], and for every i from 1 to n, A[i] can be found in B[1..p]. -- You received this message

Re: [algogeeks] Re: Subsequence

2010-08-30 Thread vikash jain
@Yan Wang..can u tel me wat u meant by saying the following : And we know all the different numbers in A[...]. we put them in a rigorously increasing sequence B[1..p], where B[1] B[2] ... B[p-1] B[p], and for every i from 1 to n, A[i] can be found in B[1..p]. -- You received this

Re: [algogeeks] Modified subset-sum problem

2010-08-30 Thread Manjunath Manohar
@rahul...well i thought..we must employ backtracking..can u pls suggest a recurrence relation for ur DP -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Will miracle ever print ?

2010-08-30 Thread Yan Wang
It's miracle can you explain? On Sun, Aug 29, 2010 at 8:07 PM, Terence technic@gmail.com wrote:  Try this: int main() {  int data = (int)0x8000; // Initialize data during run time  if ( data == -data data!=0)    printf (Miracle!!); } On 2010-8-28 1:45, Raj N wrote: int data;

Re: [algogeeks] Re: Subsequence

2010-08-30 Thread Yan Wang
Maybe I shoud use 'Levels' to express my idea. For example, A={1,0,1,0,2,2,0}, there are 7 numbers and 3 levels which is represented by an increasing array B={0,1,2}. On Mon, Aug 30, 2010 at 7:14 AM, vikash jain vikash.ro...@gmail.com wrote: @Yan Wang..can u tel me wat u meant by saying the

[algogeeks] Re: evaluate expression

2010-08-30 Thread soundar
Pl provide some test cases or more like examples -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: Subsequence

2010-08-30 Thread Dhritiman Das
This is, drawing on the idea of LCS using DP. Think, this works. Given array A[1..n] and k, fill up two more arrays , lcs[j] = max_{i=1 to j-1} lcs[i] , where A[i] = A[j] maxPrevindex[j] = i , where A[i] is max among all A[i], such that A[i] = A[j] and i ranging over 1 to j-1 This can be done

Re: [algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread Dhritiman Das
code.. void base_minus2(int n) { int x,y; if( n==0 ){ return ; } else { x = n % (-2) ; if(n0 (n%2!=0)){ n=n-1; x = 1; } base_minus2(n/(-2)); printf(%d,x); } } -- You received this message because

[algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread Dave
@vikash: Because -1 = -2 + 1 = 1*(-2)^1 + 1(*-2)^0 = 11 in place notation. Dave On Aug 30, 8:58 am, vikash jain vikash.ro...@gmail.com wrote: can you plzz tel me y -1 is interpreted as 11 ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread Piyush Verma
kar lo be itna bhi nahi kar paate :):) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For

Re: [algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread Terence
No need to handle -1 specially. 6) -2 |-1| 1 | 1| Binary : 11 On 2010-8-30 20:37, ANKIT AGGARWAL wrote: divide each number by -2 until you get -1, or 1 (Remembering that remainder is always +ve) Ex 1) -2 | 2 | 0 | -1 | Interpret -1 as 11 so binary is 110 2) -2 | 3 | 1

[algogeeks] ternary numbers

2010-08-30 Thread Raj N
In ternary number representation, numbers are represented as 0,1,-1. (Here -1 is represented as 1 bar.) How is 352/9 represented in ternary number representation? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] Will miracle ever print ?

2010-08-30 Thread Raj N
Can this be explained in context of numbers which are out of integer range ? On Mon, Aug 30, 2010 at 10:36 PM, Yan Wang wangyanadam1...@gmail.comwrote: It's miracle can you explain? On Sun, Aug 29, 2010 at 8:07 PM, Terence technic@gmail.com wrote: Try this: int main() { int

[algogeeks] Re: Amazon interview Question (Array yet again!)

2010-08-30 Thread Gene
I think your code is just the dynamic program for solving this. Let V be the set of values in the sequence A[1..N]. Then define C(n, m) to be the minimum possible cost of making A[1..n] into a new non-decreasing sequence B by decrementing and deleting elements from A with the constraint that all

[algogeeks] Re: Amazon interview Question (Array yet again!)

2010-08-30 Thread Gene
On Aug 29, 10:43 am, rahul patil rahul.deshmukhpa...@gmail.com wrote: Just read the comments.  You will get logic. 1 read global variables 2 start with main 3 read rec (a recursive fn) The main logic is that whether to keep the no in the final no (by decrementing it) or to completely

Re: [algogeeks] Re: Amazon interview Question (Array yet again!)

2010-08-30 Thread vikash jain
@gene ..if u just give an example herethat will make things more clear... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to