@rahul: I got my fault. I didn't thought about that test case. I am
thinking about applying DFS traversal algorithm for graph here. It may work
here.
On Wed, Oct 17, 2012 at 9:01 AM, Rahul Kumar Patle <
patlerahulku...@gmail.com> wrote:
> @navin: still i am not getting your solution.. can you mak
@Rahul : yes i know and actually i posted this query on geeksforgeeks.
you can find my solution in comments , search for atul007 in the provided
link.It will work for all cases. now to find all path you need to do small
modification on the same code.
On Tue, Oct 16, 2012 at 9:31 AM, Rahul Kumar Pa
@Rahul: Loop won't occur because when you are visiting any matrix element
then you are marking 1 in visited matrix. So second time it will be seen as
a already visited element and it will choose another element (or path if
exist) or will blocked.
On Tue, Oct 16, 2012 at 9:31 AM, Rahul Kumar Patle
@atul: in your solution object only can move down or right direction. but
in my problem object is free to move in any direction and hence there are ch
ances of cycle.. how to memoize cycle.
if there is cycle then your approach will give infinite solution.
consider this maze
1 1 0 0 0
1 1 0
http://www.geeksforgeeks.org/archives/13376
On Tue, Oct 16, 2012 at 8:56 AM, atul anand wrote:
> can be done simply by backtracking .
>
> On Sat, Oct 13, 2012 at 12:31 AM, Rahul Kumar Patle <
> patlerahulku...@gmail.com> wrote:
>
>> Pls help to solve this que.. does any one have DP solution for
can be done simply by backtracking .
On Sat, Oct 13, 2012 at 12:31 AM, Rahul Kumar Patle <
patlerahulku...@gmail.com> wrote:
> Pls help to solve this que.. does any one have DP solution for following
> que.
>
> http://www.geeksforgeeks.org/archives/24488
> section 5/question 2
>
> Write a program
Pls help to solve this que.. does any one have DP solution for following
que.
http://www.geeksforgeeks.org/archives/24488
section 5/question 2
Write a program to find all the possible paths from a starting point to
dest point in a maze(2-D array).
ex: 1 0 1 0
1 1 1 1
0 1 0 1
@Abhi: if you apply quick sort then again the order will will not be intact
--
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/-/ic2CXJXSGuoJ.
To post to this gr
find the element nearest to zero.make it pivot element.then apply one pass
of quicksort over the array.this is O(n)
On Thu, Jun 21, 2012 at 12:27 AM, Akshat Sapra wrote:
> void make_group( int a[], int size) {
> int j = 0;
>
> for ( int i = 0; i < size; i++ ) {
> if ( a[i] < 0
void make_group( int a[], int size) {
int j = 0;
for ( int i = 0; i < size; i++ ) {
if ( a[i] < 0 ) {
swap(a[i],a[j]);
j++;
}
}
}
--
Akshat Sapra
Under Graduation(B.Tech)
IIIT-Allahabad(Amethi Campus)
*--
@guneesh your code fails to keep order b/w 3 and 4 in the above example
On Fri, Jun 15, 2012 at 2:40 PM, Guneesh Paul Singh wrote:
> void change(int a[],int n)
> {
> int i,j;
> i=0;
> j=1;
>
> while(i {
> if(j j=i+1;
> else if(a[j]<0&&a[i]>0)
>
void change(int a[],int n)
{
int i,j;
i=0;
j=1;
while(i0)
{
swap(a,j,i);
}
else
{
if(a[j]>0)
j++;
else
i++;
}
}
}
--
You received this message because you are subscribed to th
how to do it in space comp- O(1) . I mean without using additional arrays.
Could it be done ?
On Thu, Jun 14, 2012 at 3:46 PM, utsav sharma wrote:
> @all :- by segregating 0 and 1 or by taking quicksort approach
> we have to swap no.s resulting which array becomes unordered.
>
> my approach is s
@all :- by segregating 0 and 1 or by taking quicksort approach
we have to swap no.s resulting which array becomes unordered.
my approach is start from right and if a negative no. occurs insert it
into another array temp[]
this will shift all positive no.s to right and in 2nd pass start from left
Order may not be maintained necessarily by this solution
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com
On Thu, Jun 14, 2012 at 1:47 PM, Manikanta Babu
wrote:
> Check this out, it works in O(n);
>
> int i = 0;
> int j = n-1;
>
> while
Check this out, it works in O(n);
int i = 0;
int j = n-1;
while((i= 0)&&(i0 && a[j]<0)
{
swap(a[i],a[j]);
i++; j--;
}
else
{
if(a[i]<0)
As nothing is written about space complexity, I am assuming that we can
take extra space.
Take a temporary array of length n.
1. Maintain a counter for the length of temporary array filled till now.
2. Traverse the given array. If value contained is negative insert it in
new array and update cou
Think of the +ve numbers as 0 negative numbers as 1.Now the problem reduces
to http://stackoverflow.com/questions/682171/arrange-0s-1s-in-a-array
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com
On Thu, Jun 14, 2012 at 3:00 AM, Piyush Kapoor wrote:
> your so
@Ashish @Saurabh , Recheck your solutions , order won't be maintained in
your solutions.
Its output will be = {-1 -6 -8 3 4 5 9 }
On Thu, Jun 14, 2012 at 2:08 AM, Saurabh Yadav wrote:
> @shiv relate the ashish solution with quick sort then you will understand
> easily
>
>
> On Thu, Jun 14, 2012
@shiv relate the ashish solution with quick sort then you will understand
easily
On Thu, Jun 14, 2012 at 2:06 AM, Saurabh Yadav wrote:
> +1 Ashish solution
>
>
>
> --
> Thanks & Regards
> Saurabh Yadav
>
>
--
Thanks & Regards
Saurabh Yadav
--
You received this message because you are subscr
+1 Ashish solution
--
Thanks & Regards
Saurabh Yadav
--
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 to
algogeeks+unsubscr...@goo
int i=0;
int j=n-1;
while (i0) j--;
if (iwrote:
> Given a array of integers both positive and negative and you need to shift
> positive numbers to one side
> and negative numbers to other side with the order intact.
> ex. {-1,5,3,-8,4,-6,9} to {-1,-8,-6,5,3,4,9}. This should be done in O(n).
>
> -
Given a array of integers both positive and negative and you need to shift
positive numbers to one side
and negative numbers to other side with the order intact.
ex. {-1,5,3,-8,4,-6,9} to {-1,-8,-6,5,3,4,9}. This should be done in O(n).
--
You received this message because you are subscribed t
@mithun: Try
A = 1, 6
B = 4, 3
A ^ B = 0.
Alone Ex-OR cant solve this in O(n) time.
On Monday, 21 May 2012 21:48:30 UTC+5:30, mithun wrote:
>
> By doing Ex-OR we can find if b is permutation of A
>
> suppose a -- 3 5 4
> b -- 4 3 5
> if A ^ B = 0 then both are permutation or else
By doing Ex-OR we can find if b is permutation of A
suppose a -- 3 5 4
b -- 4 3 5
if A ^ B = 0 then both are permutation or else not
shout loud if this has flaws :P
-mithun
On Sun, May 20, 2012 at 12:59 AM, HARSHIT PAHUJA wrote:
> given 2 unsorted integer arrays a and b of
we can do it bitwise...
i can set the corresponding bit by 1 of any int ...
lets take
int ia,ib=0;
and set the a[i]th bit of ia as 1 ,
and similar for bth array and ib ...
and finally check.. if(ia==ib){permutation of each other}
hope this will work..
On Sun, May 20, 2012 at 1:39 AM, malay
Agree ..
u can hardcode primes no upto certain value .
primes method works in case of permutation of alphabets .
else u can ALSO use the below method ..
find the n^2+n of each number in the array . and check for the same in the
other array .
--
You received this message because you are subscribe
@Atul007: It looks like you have three equations in n unknowns. How would
you _prove_ that these conditions are sufficient to determine whether the
arrays are permutations? My guess is that a computer search with n = 8 or
so would find a counterexample in short order.
Dave
On Sunday, May 20,
test case : -
arr[]=1 1 2 2
arr[]=0 3 0 3
without 1st condition given test case will give wrong output.
On Sun, May 20, 2012 at 1:35 PM, Darpan Baweja wrote:
> @atul:- why we require 1st condition(check sum of the square of arr1 =
> arr2) ??
>
>
> On Sun, May 20, 2012 at 1:10 PM, atul anand wrot
@atul:- why we require 1st condition(check sum of the square of arr1 =
arr2) ??
On Sun, May 20, 2012 at 1:10 PM, atul anand wrote:
> it can be done by doing set of operation on the data.
> 1) check sum of the square of arr1 = arr2
> 2) sum of elements of arr1=arr2
> 3) xoring elements of arr1 an
it can be done by doing set of operation on the data.
1) check sum of the square of arr1 = arr2
2) sum of elements of arr1=arr2
3) xoring elements of arr1 and arr2 == 0
if all 3 condition are successful then..permutation found.
On Sun, May 20, 2012 at 12:59 AM, HARSHIT PAHUJA wrote:
> given 2 un
dat defeats the o(1) space constraint. :-)
On May 19, 2012 8:05 PM, "HARSHIT PAHUJA" wrote:
> @malay --- we can do it by precomputing the prime arrays
>
>
> On Sun, May 20, 2012 at 1:10 AM, malay chakrabarti wrote:
>
>> method is ryt but to find ith prime u cannot to it in c
@malay --- we can do it by precomputing the prime arrays
On Sun, May 20, 2012 at 1:10 AM, malay chakrabarti wrote:
> method is ryt but to find ith prime u cannot to it in constant time.
> On May 19, 2012 7:30 PM, "HARSHIT PAHUJA"
> wrote:
>
>> given 2 unsorted integer arra
method is ryt but to find ith prime u cannot to it in constant time.
On May 19, 2012 7:30 PM, "HARSHIT PAHUJA" wrote:
> given 2 unsorted integer arrays a and b of equal size. Determine if b is a
> permutation of a. Can this be done in O(n) time and O(1) space ?
>
>
>
>
> please help me with my s
given 2 unsorted integer arrays a and b of equal size. Determine if b is a
permutation of a. Can this be done in O(n) time and O(1) space ?
please help me with my solution
suppose a -- 3 5 4
b -- 4 3 5
now we replace a[i] with a[i]..th prime number and b with b[i] .. th prime
i guess they were talking abt spanning tree , so you can use prism or
kruskal algo to do the same.
On Mon, Mar 12, 2012 at 3:05 PM, Umer Farooq wrote:
> Hello friends,
>
> I recently had an onsite MS interview. One of the questions that they
> asked was:
>
>
>- Given a directed graph, write
Hello friends,
I recently had an onsite MS interview. One of the questions that they asked
was:
- Given a directed graph, write a program that takes root of the graph
and returns root of a tree which comprises of all the nodes of the graph in
the same way as they appeared in the graph (
1. write a function to convert a decimal no. to Roman no. (10 marks)
2. Design a elevators system for 50 storied hotel.
condition are... at least one left should be available on ground
flore. Min. time is expected ot reach the any floore... (5 marks)
3. Design all the test case for function
@guys What's the right answer?
Sent from my BlackBerry
-Original Message-
From: "HARISH S.C"
Sender: algogeeks@googlegroups.com
Date: Wed, 2 Feb 2011 13:01:59
To:
Reply-To: algogeeks@googlegroups.com
Subject: Re: [algogeeks] Microsoft interview question
@Sarma : He
> What were your test cases?
>
> Sent from my BlackBerry
> --
> *From: * "HARISH S.C"
> *Sender: * algogeeks@googlegroups.com
> *Date: *Wed, 2 Feb 2011 01:14:00 +0530
> *To: *
> *ReplyTo: * algogeeks@googlegroups.com
> *Subject: *[
-
From: "HARISH S.C"
Sender: algogeeks@googlegroups.com
Date: Wed, 2 Feb 2011 01:14:00
To:
Reply-To: algogeeks@googlegroups.com
Subject: [algogeeks] Microsoft interview question
We have a text editor application where we can choose 1)between 100s of
different fonts like arial,calib
We have a text editor application where we can choose 1)between 100s of
different fonts like arial,calibri,etc.. 2)different text sizes 3) different
formatting such as bold, Italics,regular,etc..
Imagine that the application is similar to word(there we will have these
options). Now give different
http://cslibrary.stanford.edu/109/TreeListRecursion.html
--
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...@goo
see careercup.com
On Sat, Dec 18, 2010 at 1:49 AM, anujbhambhani wrote:
> write a recursive function to convert a BST into sorted doubly linked
> list.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email
write a recursive function to convert a BST into sorted doubly linked
list.
--
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
algoge
I can only think of one way off the top of my head:
class IndexedDocument {
HashTable index;
String contents;
/// Build an index of words and their position in the document
void buildIndex() {
for each word in document {
add word, position to index
}
then u can just use or build a dynamic dictionary of words as done in LZW
coding such that if the word is there in the dictionary it just gives u the
indx of the word and if its not it just adds that word to the dictionary any
suggestions are always welcomed thnx in advance
On Fri, Dec 10, 2010 at
it will give you an idea.
http://en.wikipedia.org/wiki/Full_text_search
On Fri, Dec 10, 2010 at 4:03 PM, ADITYA KUMAR wrote:
> @ankit
> u can'nt use TRIE
> becoz , input will be given in form of text
> so generating the TRIE will be much expensive than linear search
>
> On Fri, Dec 10, 2010 at
@ankit
u can'nt use TRIE
becoz , input will be given in form of text
so generating the TRIE will be much expensive than linear search
On Fri, Dec 10, 2010 at 3:13 PM, GOBIND KUMAR wrote:
> Help me in solving this problem... Define a data struct for the search
> engine which will represent
just search for the word in the document using an efficient string matching
algorithm
use Knuth Morris Pratt algorithm as it runs in O(m) time.
or use a data structure called TRIE
where u can search for the word in O(1) time any suggestions are always
welcomed
On Fri, Dec 10, 2010 at 3:13 PM, GOB
Help me in solving this problem... Define a data struct for the
search engine which will represent whether
given word is there in the document or not .It should be fast.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this
Hello,
2010/12/4 siva viknesh :
> Modified 2 color sort problem i.e. you are given an array of integers
> containing only 0s and 1s.You have to place all the 0s in even
> position and 1s in odd position. And if suppose, no. of 0s exceed no.
> of 1s or vice versa then keep them untouched. Do that
My bad, did not see the in-place memory requirement
On Sat, Dec 4, 2010 at 8:49 PM, coolfrog$
wrote:
> @shreyas VA
> you are using O(n) extra space...
>
>
> On Sat, Dec 4, 2010 at 8:46 PM, Shreyas VA wrote:
>
>> Given the size of the input array,
>> construct array1 = {0, 1, 0, 1} till n e
@shreyas VA
you are using O(n) extra space...
On Sat, Dec 4, 2010 at 8:46 PM, Shreyas VA wrote:
> Given the size of the input array,
> construct array1 = {0, 1, 0, 1} till n elements
>
> traverse through input array checking sum of 1's n 0's.
>
> at the end if both sums are equal return a
Given the size of the input array,
construct array1 = {0, 1, 0, 1} till n elements
traverse through input array checking sum of 1's n 0's.
at the end if both sums are equal return array1 else return input array.
On Sat, Dec 4, 2010 at 12:06 AM, siva viknesh wrote:
> Modified 2 color sort p
here base index is 1 and total no. of elements are n.
k=1;
i=1;
while(i wrote:
> I hope the following approach will work.
> Let 'a' be the input array with size n.
>
> int i = 0, j = 1;
>
> while( true)
> {
> while( i < n && a[i] == 0) i += 2;
> while( j < n && a[j] ==
I hope the following approach will work.
Let 'a' be the input array with size n.
int i = 0, j = 1;
while( true)
{
while( i < n && a[i] == 0) i += 2;
while( j < n && a[j] == 1) j += 2;
if ( i < n && j < n ) swap(a[i], a[j]);
if ( i > n && j < n ) {
Modified 2 color sort problem i.e. you are given an array of integers
containing only 0s and 1s.You have to place all the 0s in even
position and 1s in odd position. And if suppose, no. of 0s exceed no.
of 1s or vice versa then keep them untouched. Do that in ONE PASS and
without taking extra memo
Asked in microsoft interview
"Given a snapshot of an ongoing chess game, which probably is a one vs many
game, identify whether it is a valid game or not."
It would be great if someone would clarify on what conditions does
"validity" of the game depend..
--Vrinda
--
You received this message
use a array
arr[char]=count char represent say a-z
count is # of occurances
while (*s!='\0')
{
arr[*s-'a']++;
if (arr[*s-'a']==1) lastchar=*s;
}
lastchar is the last non repeating char
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Sun, Aug
How to find last unique character in a given string. Unique character
means non-repeated number. Give an optimized way.
--
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 unsubs
61 matches
Mail list logo