Your solution fails for a number of reasons:
1. If your array is size 1 or 0.
2. The last digit in the array is found by arr[n-1] - [n-2] not
arr[i+1]-arr[i]
3. Recursion here creates unnecessary overheard
How many times are you calling abc? Draw the recursion tree.
On Tue, Apr 9, 2013 at 11:29
A = {5, 3, 8, 9, 16}
After one iteration A = {3-5,8-3,9-8,16-9}={-2,5,1,7}
After second iteration A = {5-(-2),1-5,7-1} sum =7+(-4)+6=9
Given an array, return sum after n iterations
my sol/
void abc(int arr[],n)
{
for(i=0;ihttps://groups.google.com/groups/opt_out.
@Rashmi: I did not get your approach. I do not get emails from the group
just in case you have posted a solution :( What do you mean by keeping a
count? Also, are you using a hashmap? If yes, whats ur K,V?
#Pralay
On Tue, Feb 12, 2013 at 10:00 AM, rashmi i wrote:
> Hey Pralay,
> Sorry, if I
Hey Pralay,
Sorry, if I have missed any point.Why would we need to map the
frequencies when the second problem can be solved by simply keeping a count
and comparing the index values that have been already mapped.
On Fri, Feb 8, 2013 at 11:19 AM, sourabh jain wrote:
> One solution for the 2n
One solution for the 2nd question can be LinkedHashMap (linked list +
hashmap) .
Store the integer in linked list in the order of occurrence in stream and
make an entry in hashmap on first occurence. Delete the integer entry from
linked list on 2nd occurence and replace the reference with some spec
first problem can be solved using a fixed sized array if we know the
range of numbers or a hash table with an appropriate hash function and
it is O(N) for time and space as some solutions above already
mentioned this.
for the second problem, I don't think heap is the right data structure
which is
Guys,
Why can't we simply use a hashset for both the questions. hash the arr[i]
and the frequencies in the hash map in the first pass. Then iterate over
the array to find the first arr[i] whose freq is 1 in the hash map. For
second part, keep a count and find the kth element in the array whose freq
@sourabh : how do u find whether the element in stream gets repeated in
heap.--> O(n) time...totally its O(nk) algo ..
If we maintain max-heap with BST property on index, then it would be
O(nlogk).
On Wed, Feb 6, 2013 at 12:25 PM, sourabh jain wrote:
> for 2nd question you can make a heap with
for 2nd question you can make a heap with their index as a factor to
heapify them. whenever a integer in stream gets repeated you just nead to
remove it from heap and heapify it.
On Wed, Feb 6, 2013 at 10:00 AM, navneet singh gaur <
navneet.singhg...@gmail.com> wrote:
> nice algo ankit, so it wi
Navneet,
For 2nd problem, i need a clarification, whether the Kth number is wrt
mathematical ordering of numbers or
the kth number is wrt to the order in which the number are input ?
On Wed, Feb 6, 2013 at 10:00 AM, navneet singh gaur <
navneet.singhg...@gmail.com> wrote:
> nice algo ankit, so
what would happen of the input is like this : 5, 5, 66, 66, 7, 1, 1, 77,7
i think in this case the moment window reaches to point (66,7,1) it will
take 7 as unique number but
that too window will not move any futhur , but 7 is not unique .
Please comment if i misunderstood ur explanation .
O
Also, for the part two of the question, you can simply go in for the *kth
largest positive index *in the same hashmap (described earlier for part 1).
That solves the part two of the problem :)
Hth,
*Pralay Biswas*
*MS,Comp Sci, *
*University of California, Irvine*
On Tue, Feb 5, 2013 at 8:46 PM, P
I guess the part 1 can be solved in O(n) time and space both. Here is my
approach.
Assume: Array given is arr[] = {2,3,1,2,3,2,4,1,5,6}
1. Given an array, scan thru it, element by element and hash it on a
hashmap with key as the arr[i] as the key and i+1 as the index.
2. There would be two cases
was trying to do something clever. Knew it couldnt be that simple. Missed
some cases. I still feel with some hacks and handling some special cases
this approach would work.
But considering it still takes O(n) time I am not thrilled. I am still ok
with my algo taking Space for time. But probably
@srikar :
approach2 is wrong.
ex: [1, 5, 7, 66, 7, 1, 77]
first window [1,5,7] all are unique.oops
On Wed, Feb 6, 2013 at 11:31 PM, Srikar wrote:
> *APPROACH 1:*
> use a hashtable for both the questions ?
>
> Insert the integers as they are given in the array into a hashtable. The
> stru
*APPROACH 1:*
use a hashtable for both the questions ?
Insert the integers as they are given in the array into a hashtable. The
structure I am thinking is key (the integer) -> [index]. Once all elements
are inserted. Run through the hashtable and select the one which has
len(value) == 1 and is lea
nice algo ankit, so it will be nlogn using O (n) space only. What abt
2nd Q., which have a big online stream.
On Mon, Feb 4, 2013 at 9:30 PM, kumar ankit wrote:
> For 1:
> i think you can use sorting, sort the array and keep the indices of the
> numbers in the sorted list.
> Now traverse the sort
For 1:
i think you can use sorting, sort the array and keep the indices of the
numbers in the sorted list.
Now traverse the sorted list and in the sorted list you need to find the
unique number with the
minimum index which is easy to find.
Eg: Array:5 3 1 2 4 1 4
Indices: 0 1 2 3 4 5 6
in above algo primary index is no of times that value is repeated till now
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to algogeeks+unsubscr...@googlegroups.
I can think of an o(n^2) algo for 2n question
Make a heap formed acctoring to two indexes
1.Primary -value
2.Secondary - index
Now for each new incoming value first search in head if exist inc its index
else make a new node
--
You received this message because you are subscribed to the Google Gr
1. Given a array,find a first unique integer.
2. Integers are coming as online stream,have to find a kth unique integer
till now.
For 1.
Even we cannot use sorting for solving this as if we sort it than our first
number which is non-repetitive changes.
The best I am able to do is nlogn using a
loop from the end of given number till you get a digit less than the
previously scanned digit.Let the index of that number be 'i' .
if index = -1,then the given number is the largest one
else do the following
1) swap the digit at the index i with the digit just greater than it in the
scanned porti
For a given number, find the next greatest number which is just greater
than previous one and made up of same digits.
--
Given an array of integers where some numbers repeat once, some numbers
repeat twice and only one number repeats thrice, how do you find the number
that gets repeated 3 times?
Does this problem have an O(n) time and O(1) space solution?
No hashmaps please!
--
You received this message because yo
@ashgoel - Could you please explain what exactly are you doing here ?
On Wednesday, 4 July 2012 16:16:38 UTC+5:30, ashgoel wrote:
>
> Q4
>
>
> vector prefix;
> prefix[0]=NULL;
> prefixCount =1;
> for (int i=0;i for (int j=0;j for (int k=0; k {
> if (visited[i][j]) continue;
>
Sorry i typed wrongly
tree is
2
1 3
preorder traversal is 123 and same for other tree as well. Please check !
On Wed, Jul 4, 2012 at 5:24 PM, a g wrote:
>
> 1
> 2 3 is not a BST and its pre-order traversal is 1 2 3, pre
> order of other is 3 2 1 .
>
1
2 3 is not a BST and its pre-order traversal is 1 2 3, pre
order of other is 3 2 1 .
On Wed, Jul 4, 2012 at 5:17 PM, Bhupendra Dubey wrote:
> Consider trees:
>
> 1 3
>2 3 2
>
For question 5.
Even this doesn't seems right
Consider this scenario
Match b/w Winner
a vs b a
a vs c c
b vs c b
What will be order ?? acb or bca
On Wed, Jul 4, 2012 at 5:38 PM, Bhupendra Dubey wrote:
> 1. For fir
1. For first question trie of given word will be best option.
Space complexity O(total length of words) (worst case)
Time complexity O(T) . T length of input text (Newspaper)
2. consider it to be a 4 digit number ABCD . Find maximum Most
significant digit say it is C , and out of these nos
Consider trees:
1 3
2 3 2
1
pre order traversal is same still (1 , 2 ,3) even though ist tree doesn't
satisfy the criteria . So I don't think it can be determi
Q4
vector prefix;
prefix[0]=NULL;
prefixCount =1;
for (int i=0;i wrote:
> 1. inverted hasp map
> 2. not clear
> 3. VLR, how do you identify end of L and start of R, question incomplete
> 4. One problem: consider
>
> ...
> a b...
> c d...
> ...
>
> if ab is a prefix, can aba be another pr
Q5 is sorting problem
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Wed, Jul 4, 2012 at 4:13 PM, Ashish Goel wrote:
> 1. inverted hasp map
> 2. not clear
> 3. VLR, how do you identify end of L and start of R, question incomplete
> 4. One probl
1. inverted hasp map
2. not clear
3. VLR, how do you identify end of L and start of R, question incomplete
4. One problem: consider
...
a b...
c d...
...
if ab is a prefix, can aba be another prefix, i would assume so. But if
that is true, i am not sure if this program will come to an end
Have answered inline:
Q1) Given a newspaper and a set of ‘l’ words, give an efficient
algorithm to find the ‘l’ words in the newspaper.
Trivial hash-dictionary search operation. Takes O(m*l), where m=length
of maximum length word in the set l.
Q2) Find the next higher number in set of permutation
Q1) Given a newspaper and a set of ‘l’ words, give an efficient algorithm
to find the ‘l’ words in the newspaper.
Q2) Find the next higher number in set of permutations of a given number.
Q3) Given preorder of a BST, find if each non-leaf node has just one child
or not. To be done in linear tim
Hashmap can be used for effective retreival..
On Thu, Jun 14, 2012 at 4:23 PM, Mohit Rathi wrote:
> arr1 = [abc,xyz,lmn,def]
> arr2 = [3,6,2,8]
>
> if user enters "xyz" then 6 will be printed
> else
> if xyz doesn't exist in arr1 then ask for a number and add them in
> respective arrays(name in
Since the size of array is very less I think Hashmap is the best.
Use name as the hash key and number as its value.
On Thursday, June 14, 2012 6:46:34 PM UTC+5:30, utsav sharma wrote:
>
> it can be done using map in c++
>
> On Thu, Jun 14, 2012 at 4:23 PM, Mohit Rathi wrote:
>
>> arr1 = [abc,xyz,
it can be done using map in c++
On Thu, Jun 14, 2012 at 4:23 PM, Mohit Rathi wrote:
> arr1 = [abc,xyz,lmn,def]
> arr2 = [3,6,2,8]
>
> if user enters "xyz" then 6 will be printed
> else
> if xyz doesn't exist in arr1 then ask for a number and add them in
> respective arrays(name in arr1 and numbe
arr1 = [abc,xyz,lmn,def]
arr2 = [3,6,2,8]
if user enters "xyz" then 6 will be printed
else
if xyz doesn't exist in arr1 then ask for a number and add them in
respective arrays(name in arr1 and number in arr2).
Hope it helps
On Thu, Jun 14, 2012 at 3:58 PM, utsav sharma wrote:
> example pls...
>
example pls...
On Thu, Jun 14, 2012 at 1:01 PM, Mohit Rathi wrote:
> Hi,
>
> *There are two arrays of length 100 each. Each of these has initially n
> (n<=100)
> elements. First array contains names and the second array contains numbers
> such that ith name in array1 corresponds to ith number in
Hi,
*There are two arrays of length 100 each. Each of these has initially n
(n<=100)
elements. First array contains names and the second array contains numbers
such that ith name in array1 corresponds to ith number in array2.
Write a program which asks the user to enter a name, finds it in array1,
refer http://www.cs.bell-labs.com/cm/cs/pearls/sol01.html
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Thu, May 24, 2012 at 6:00 PM, Ashish Goel wrote:
> What is the purpose of these numbers, if the idea is to manage a free
> pool, then proba
What is the purpose of these numbers, if the idea is to manage a free pool,
then probably 10-ary-tree is the solution. May be Tiger Tree Hash a better
answer where it is tree to say level 7 and then for rest three digits it
become hash table. This way, the chunks can be kept on different machines
t
array of bits?
if the current integer is present set the bit if else make it zero,
searching, insertion and deletion all in O(1) time.
On Thu, May 24, 2012 at 4:15 PM, rishabh shukla wrote:
> Suggest a data structure for storing million trillion numbers efficiently
> in very less space. Means sp
Suggest a data structure for storing million trillion numbers efficiently
in very less space. Means space complexity should be as less as possible
--
Rishabh Shukla
B.Tech Final Year
MNNIT Allahabad
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks"
@bharat: +1
On Thu, Apr 26, 2012 at 1:06 PM, bharat b wrote:
> create an array of linked lists.. each index in the array represents the
> node number and the linked list of that represents edges of that node.
--
You received this message because you are subscribed to the Google Groups
"Algorit
No limit on #nodes and #edges.
On Thu, Apr 26, 2012 at 1:06 PM, bharat b wrote:
> In input, he mentions #nodes and #edges of each nodes has, right?
> create an array of linked lists.. each index in the array represents the
> node number and the linked list of that represents edges of that node.
>
adjacency list
On Apr 25, 2012, at 5:40 PM, Radhakrishnan Venkataramani wrote:
> How will you implement a graph data structure ?
> Give an linked implementation as we do not know how many nodes will be there
> and how many edges will be there.
> Make a copy of this graph..
>
>
>
> --
> You
What will be the size of the array? You don't know the number of nodes in
the graph. Implementing table doubling would be tedious.
If they asked for a specific language implementation then for c++ you can
use a vector of linked lists.
Otherwise a linked list of pointers to head of linked lists wou
In input, he mentions #nodes and #edges of each nodes has, right?
create an array of linked lists.. each index in the array represents the
node number and the linked list of that represents edges of that node.
Am I right?
On Wed, Apr 25, 2012 at 5:40 PM, Radhakrishnan Venkataramani <
radhakrishnan
How will you implement a graph data structure ?
Give an linked implementation as we do not know how many nodes will be
there and how many edges will be there.
Make a copy of this graph..
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To pos
@all Please check the Backtracking examples at
http://www.geeksforgeeks.org/archives/tag/backtracking.
You will understand the logic.
In this examples first we fix a no. onto some position. After we check for
other no. if any of the no. do not fit according to property we move back
and reset all t
@all : if see the code closely ...logic is simple.
code is just trying many permutation to find an answer.
say input = 6
now assuming that 6 will be placed at position arr[i] and arr[j+i+1] . it
will put that value and move further to find next possible location for
input-1;
at any point of time
@ Neeraj: Plz explain ur logic.
--
Ravi Shankar
MCA 2nd Year
Department Of Computer Science
University Of Delhi
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe
Coding Geek, if you have understood the algo provided by Neeraj, request
you to explain the logic please.
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Thu, Jan 19, 2012 at 8:03 PM, Coding Geek wrote:
> @Neeraj
> Thanx for providing the algo
@Neeraj
Thanx for providing the algo
On Thu, Jan 19, 2012 at 7:18 PM, rahul patil
wrote:
> Looks like classic example of backtrack !!!
>
>
> On Thu, Jan 19, 2012 at 1:05 PM, Prakash D wrote:
>
>> ignore my last comment.. misunderstood
>>
>>
>> On Thu, Jan 19, 2012 at 1:04 PM, Prakash D wrote:
>
Looks like classic example of backtrack !!!
On Thu, Jan 19, 2012 at 1:05 PM, Prakash D wrote:
> ignore my last comment.. misunderstood
>
>
> On Thu, Jan 19, 2012 at 1:04 PM, Prakash D wrote:
>
>> why can't u simply place it as 1 2 3 4 5 6 7 1 2 3 4 5 6 7?
>>
>>
>> On Thu, Jan 19, 2012 at 2:05 A
why can't u simply place it as 1 2 3 4 5 6 7 1 2 3 4 5 6 7?
On Thu, Jan 19, 2012 at 2:05 AM, NEERAJ KODDHAN wrote:
> int[] a = new int[2*n];
> put(a, n);
>
> static void put(int[] a,int i){
> if(i>0){
> for(int j=0;j if(a[j]==0 && a[j+i+1]==0){
> a[j]=i;
> a[j+i+1]=i;
> put(a, i-1);
> a[j]=0;
ignore my last comment.. misunderstood
On Thu, Jan 19, 2012 at 1:04 PM, Prakash D wrote:
> why can't u simply place it as 1 2 3 4 5 6 7 1 2 3 4 5 6 7?
>
>
> On Thu, Jan 19, 2012 at 2:05 AM, NEERAJ KODDHAN wrote:
>
>> int[] a = new int[2*n];
>> put(a, n);
>>
>> static void put(int[] a,int i){
>>
i guesscomplexity would be O(2^n)
no output for 5 and 9
On Thu, Jan 19, 2012 at 3:59 PM, ADITYA KUMAR wrote:
> thats a brute force solution...
> can u expalin the complexity..i think its O(n^2)
> and also there exist no solution for n < 3
>
>
> On Thu, Jan 19, 2012 at 3:36 PM, bharat b wrote
thats a brute force solution...
can u expalin the complexity..i think its O(n^2)
and also there exist no solution for n < 3
On Thu, Jan 19, 2012 at 3:36 PM, bharat b wrote:
> @Neeraj : will u pls explain u'r logic ...
>
> On 1/19/12, NEERAJ KODDHAN wrote:
> > int[] a = new int[2*n];
> > put(a, n
@Neeraj : will u pls explain u'r logic ...
On 1/19/12, NEERAJ KODDHAN wrote:
> int[] a = new int[2*n];
> put(a, n);
>
> static void put(int[] a,int i){
> if(i>0){
> for(int j=0;j if(a[j]==0 && a[j+i+1]==0){
> a[j]=i;
> a[j+i+1]=i;
> put(a, i-1);
> a[j]=0;
> a[j+i+1]=0;
> }
> }
> }else if(i==0
int[] a = new int[2*n];
put(a, n);
static void put(int[] a,int i){
if(i>0){
for(int j=0;jwrote:
> Place N number from 1 to N, in 2N positions in such a way so that there
> are
>
> Exactly “n” number of cells between two placed locations of number “n”.
> Write a program to display numbers placed
Place N number from 1 to N, in 2N positions in such a way so that there are
Exactly “n” number of cells between two placed locations of number “n”.
Write a program to display numbers placed in this way.
Example:-
(1) One of the possible placement for 7 numbers in 14 positions is :
5 7 2 3 6 2 5
also I dont think that for case 0 we do not need to have one ++. I guess it
fails for this example
2200101
On Mon, Jan 2, 2012 at 5:36 PM, Arun Vishwanathan wrote:
> @utkarsh: in yr code it shud be two-- after the swap function and not
> before for case 2
>
>
> On Thu, Nov 10, 2011 at 1:25 PM, U
@utkarsh: in yr code it shud be two-- after the swap function and not
before for case 2
On Thu, Nov 10, 2011 at 1:25 PM, UTKARSH SRIVASTAV
wrote:
>
>
> sorry it was incomplete
>
>
> On Fri, Nov 11, 2011 at 2:53 AM, UTKARSH SRIVASTAV <
> usrivastav...@gmail.com> wrote:
> one = zero = 0;
> two = n-
I think smallest will be having just one character . it can be a or b or c.
On Sat, Nov 12, 2011 at 3:07 PM, Snoopy Me wrote:
> Given a string consisting of a,b and c's, we can perform the following
> operation:
> Take any two adjacent distinct characters and replace it with the
> third charact
Given a string consisting of a,b and c's, we can perform the following
operation:
Take any two adjacent distinct characters and replace it with the
third character. For example, if 'a' and 'c' are adjacent, they can
replaced with 'b'.
What is the smallest string which can result by applying this
one = zero = 0;
two = n-1; //n is length of string
while(two>=one)
{
switch(a[one])
On Mon, Oct 24, 2011 at 9:50 PM, praveen raj wrote:
> This can be done in O(n)..
>
> first shift all the 2's to the right side in O(n)...
>
> then again shift 1to the right shift b efore 2's. in O
sorry it was incomplete
On Fri, Nov 11, 2011 at 2:53 AM, UTKARSH SRIVASTAV
wrote:
one = zero = 0;
two = n-1; //n is length of string
while(two>=one)
{
switch(a[one])
{
case '0' : swap(a[zero],z[one]);
one++;zero++;break;
case '1' : one++;
break;
case
This can be done in O(n)..
first shift all the 2's to the right side in O(n)...
then again shift 1to the right shift b efore 2's. in O(n)...
With regards,
Praveen Raj
DCE-IT 3rd yr
735993
praveen0...@gmail.com
On Mon, Sep 26, 2011 at 6:23 PM, Naren s wrote:
> dutch national fl
dutch national flag problem..search in wiki...classical.
On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI wrote:
> You are given a string (consisting of 0's, 1's or 2's) where 0
> represents a blue ball, 1 a
> red ball, and 2 a black ball. Using only swap operations (counting
> sort not allowed)
> rearr
count the number of 0s 1s 2s.then store os first den 1s followed by 2s
On Sat, Sep 24, 2011 at 9:55 AM, Anup Ghatage wrote:
> Is this like the segregating all the 1's to the right and the 0's to the
> left
> or am i missing something?
>
>
> On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI wrote:
>
>> Y
@guarav true
@others no point in sending the code describe your logic... anyway link
provided by guarav is suffice to solve the problem
On Sat, Sep 24, 2011 at 5:26 PM, Gaurav Aggarwal wrote:
> Classic problem http://en.wikipedia.org/wiki/Dutch_national_flag_problem
>
>
>
> On Sat, Sep 24
Keep two pointers - p1 and p2
p1 points at the index just after last 0 such that there are all zero's
before it.
p2 points at the entry just before last 2, and there are all 2's after it.
*example*- 0010201201222
p1 = 2; p2 = 9;
*Pseudo code - *
p1 = 0;
p2 = n-1;
i = 0;
while(i wrote:
> we cant
Classic problem http://en.wikipedia.org/wiki/Dutch_national_flag_problem
On Sat, Sep 24, 2011 at 5:15 PM, Ankur Garg wrote:
> void sort012(int a[],int n){
> int i = 0, s = 0, last = n-1;
> while(i<=last){
>if(a[i] == 0 && i!=s)
> {
>swap(a[i], a[s]);
>s+
void sort012(int a[],int n){
int i = 0, s = 0, last = n-1;
while(i<=last){
if(a[i] == 0 && i!=s)
{
swap(a[i], a[s]);
s++;
}
else if(a[i] == 2 && i!=last)
{
swap(a[i], a[last]);
last--;
}
else
i++;
}
}
On Sat, Sep 24, 2011 at 5:13
I think this will do the same: -
#include "stdafx.h"
#include "stdlib.h"
void swap(int *a, int start, int end)
{
int temp;
temp = *(a + start);
*(a + start) = *(a + end);
*(a + end) = temp;
}
int _tmain(int argc, _TCHAR* argv[])
{
int minIndex=0, maxIndex=
dutch national flag problem :)
On Sat, Sep 24, 2011 at 3:45 PM, Dheeraj Sharma wrote:
> i think this travels only once ... correct me if am wrong
> #include
> #include
> #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c)
> int main()
> {
> int t,x;
> scanf("%d",&t);
> while(t--)
> {
>
i think this travels only once ... correct me if am wrong
#include
#include
#define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c)
int main()
{
int t,x;
scanf("%d",&t);
while(t--)
{
char str[100];
scanf("%s",str);
int i=0,j=0,k=strlen(str)-1;
we cant traverse the string twice...
if there is an error in my logic then plz tell
my logic is:
we have to take starting and ending indexes for '0','1','2' like below
0 1 2
starting_index
ending_index
now suppose our string "102112011"
so w
char str[100],t;
scanf("%s",str);
char ch='0';
int i=0,j=0;
while(j wrote:
> Is this like the segregating all the 1's to the right and the 0's to the
> left
> or am i missing something?
>
>
> On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI wrote:
>
Is this like the segregating all the 1's to the right and the 0's to the
left
or am i missing something?
On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI wrote:
> You are given a string (consisting of 0's, 1's or 2's) where 0
> represents a blue ball, 1 a
> red ball, and 2 a black ball. Using only swap
You are given a string (consisting of 0's, 1's or 2's) where 0
represents a blue ball, 1 a
red ball, and 2 a black ball. Using only swap operations (counting
sort not allowed)
rearrange the string such that all blue balls are together on one
side, followed by all red
balls, and then all black balls
@Ravi
+1
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/E0NIFwY150EJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from
space of integer depends on the machine you are using. Eg. 32 bit system int
would take 4 bytes. Space taken by the pointer is equal to the space of
address it needs to store. Here it will take 4 bytes to save the address of
a integer.
Correct me if I am wrong.
On Fri, Sep 16, 2011 at 9:23 PM, Rah
How much space does a pointer and integer takes?
For eg :-
int a;
int *a;
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/RmPHywrTUbkJ.
To post to this grou
Given an N arrays of size K each.. each of these K elements in the N
arrays are sorted, each of these N*K elements are unique. Choose a
single element from each of the N arrays, from the chosen subset of N
elements. Subtract the minimum and maximum element. Now, this
difference should be least pos
I tried implementing the problem.
Working code is:
#include
void print_arr(int* arr, int len)
{
int i;
printf("\n Array is \n");
for (i = 0; i < len; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}
int get_right_index(int i, int len)
{
if (i < len/2) {
@above, "if initial position=final position or the final position was
empty,then choose the next element(element next to the initial position) as
current element"
How do you guarantee when you move to the next element, the next element is
not already processed? Otherwise, you will double process o
algo in more detail :-o
if the array is numbered from 0..(2n-1)
i= initial position of int/char
f= final position of int/char
if (i < (2n-1)/2) #for integer
f = i+i
else #for char
f = i - ((2n-1)-i)
so iterate through the array in the following way
choose first element
determine it final posit
thr is some error in algo
On Mon, Feb 7, 2011 at 10:48 PM, abc abc wrote:
> I would like to have pseudo for this .
>
> On Mon, Feb 7, 2011 at 11:12 AM, jalaj jaiswal
> wrote:
>
>> A very common interview question
>>
>> let the array be from 0 to 2n-1
>>
>> now,
>>
>> every element of array has
I would like to have pseudo for this .
On Mon, Feb 7, 2011 at 11:12 AM, jalaj jaiswal wrote:
> A very common interview question
>
> let the array be from 0 to 2n-1
>
> now,
>
> every element of array has its initial position and final position.. start
> from beginning
> if the elemnt you r proce
A very common interview question
let the array be from 0 to 2n-1
now,
every element of array has its initial position and final position.. start
from beginning
if the elemnt you r processing is the first half of array then f=i+i;
else f=2*i-(2n-1);
replace the elemnt at final position with the i
If [a1,a2,a3...,an,b1,b2...bn] is given input change this to
[a1,b1,a2,b2.an,bn]
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email
Given a boolean matrix with all the true elements on left side in the row so
that each row can be broken into two parts left part containing only true
elements and right part containing only false elements. Find the row with
max number of true elements in it.
00011
0
1
true is 0 false is
@Nikhil: ya..rt
--
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 more options, visit th
@Saurabh You used an extra pointer compared to shiva's code ,you can avoid
that. :)
On Mon, Dec 20, 2010 at 8:24 PM, Saurabh Koar wrote:
> @Rishi:I think Shiva's code is also fine.U can access the list easily
> by using down pointer in his code.
> Because he is assigning temp->down=temp2 and then
@Rishi:I think Shiva's code is also fine.U can access the list easily
by using down pointer in his code.
Because he is assigning temp->down=temp2 and then he is making temp->fwd=NULL.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to
@Rishi:I think Shiva's code is also fine.U can access the list easily
by using down pointer in his code.
Because he is assigning temp->down=temp2 and then he is making temp->fwd=NULL.
On 12/20/10, Saurabh Koar wrote:
> temp=head;
> temp1=temp->fwd;
> while(temp->fwd!=NULL)
> {
> temp2=temp;
>
1 - 100 of 114 matches
Mail list logo