I think there is a problem in this solution.
U r accessing stack elements from 1 to n in the outer loop. It is not
possible. 1st element cannot be accessed without popping first n-1 elements
out.
On Mon, Jun 18, 2012 at 11:33 AM, Rituraj wrote:
> My iterative approach
>
> /*code in c*/
> #includ
this is not a stack at all, u have just named it as a stack. for it to be a
stack u should access only the top most element at any point of time!!!
On Mon, Jun 18, 2012 at 11:33 AM, Rituraj wrote:
> My iterative approach
>
> /*code in c*/
> #include
> int main()
> {
> int stack[]={1,2,3,4,5,6,
In a stack, you can't access any element directly, except the top one.
On Mon, Jun 18, 2012 at 11:33 AM, Rituraj wrote:
> My iterative approach
>
> /*code in c*/
> #include
> int main()
> {
> int stack[]={1,2,3,4,5,6,7,8},top=7;//
> int i,j,temp;
>
> for(i=1;i<=top;i++)
> {
> temp=stack[i
1 search should in using KMP algo so that It can be seacrh in O(n) . let
function is int KMP(src,trget, searchDirection )
this kmpSearch funtion should be implemented is such a fashion that is
search in both direction.
3. assume that give 2d array name is array
const int row =1;
const int col =1
@utsav
in cases where u have repeating character in ur search string how would u
assign the numbers
eg in abaac
--
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 fr
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Fri, Jun 8, 2012 at 12:54 PM, Ashish Goel wrote:
> #include "stdafx.h"
> #include
> using namespace std;
>
> const int len = 20;
> const int maxCount = 127;
>
> int rle(char* pStr, int length, cha
#include "stdafx.h"
#include
using namespace std;
const int len = 20;
const int maxCount = 127;
int rle(char* pStr, int length, char* pNew) {
if (!pStr) return -1;
if (length <3) return -1;
int i = 0;
int k = 0;
char p1 = pStr[i++];
char p2 = pStr[i++];
char p3 = pStr[i++];
int pos=0;
int cC
The idea here is that there will be parts of the stream which actually
should not be compressed. For example abcdef as well as aa do not need any
compression. We need to compress only if 3 characters match because for
compressing two chars we will take up 2 chars so no compression benefit (:
So we
If abcdef is changed to a1b1c1d1e1f1,
then we need to allocate memory dynamically.
Because length is increased,I think this has no practical
implementation.As "abcdef " serves the same purpose.
On Sunday, 3 June 2012 09:36:25 UTC+5:30, utsav sharma wrote:
>
> @ashish:-algo given in link wiil fa
Try this code...i think my code can be improved further.
#include
main()
{
int flag=0;
int i;
int c,prev;
int chars[26];
for(i=0;i<26;i++)
chars[i]=0;
while((c=getchar())!=EOF)
{
if(flag==0)
{
prev=c;
flag=1;
}
if(c==prev)
{
if(c>='a' && c<='z')
++chars
@ashish:-algo given in link wiil fail for "abcdef"
@navin:- output of "abcdef" should be "1a1b1c1d1e1f"
On Sun, May 27, 2012 at 3:24 PM, Ashish Goel wrote:
> Will fail for the sing having say 257characters all same
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +91
Will fail for the sing having say 257characters all same
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Sat, May 26, 2012 at 12:26 PM, Navin Gupta wrote:
> This is called Run-Length-Encoding (RLE) of a string.
> Its purpose is to save space.So
http://michael.dipperstein.com/rle/index.html
and basic one is
http://www.fileformat.info/mirror/egff/ch09_03.htm
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Sat, May 26, 2012 at 1:10 PM, Hassan Monfared wrote:
> 1- try "a
1- try "abb"
On Sat, May 26, 2012 at 12:07 PM, Anchal Gupta wrote:
> yeah i forgot inplace so to do that we simply add count and ch in str
> input array instead of op.
> btw whats wrong with count it give me right answer.
>
> On May 26, 12:08 pm, Hassan Monfared w
u forgot to do "inplace" and you have wrong conversion of count
On Sat, May 26, 2012 at 11:31 AM, Anchal Gupta wrote:
> hey, here is the function that do the compression and store the output
> in an array op.
>
>
> void str_comp(char *str)
> {
> int count=0,j=0,i;
> char ch,op[100];
>
> for(i=
Steps:
1)Reverse the list ...
2)Now do the swap two nodes... consecutively...
PRAVEEN RAJ
DELHI COLLEGE OF ENGINEERING
--
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 unsubs
oh, a possible mistake from my side, ignore my mail please...
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Tue, Jan 24, 2012 at 3:08 PM, atul anand wrote:
> @Ashish : seems exactly similar to Lucifer code or you modified something
> in his
node* prev(node *h)
{
node *p,*q,*r;
p=h;
q=p->next->next;
p->next->next=NULL;
while(q!=NULL)
{
r=q->next->next;
q->next->next=p;
p=q;
q=r;
}
return p;
}
On Tue, Jan 24, 2012 at 3:08 PM, atul anand wrote:
> @Ashish : seems exact
@Ashish : seems exactly similar to Lucifer code or you modified something
in his code ?? ...
On Tue, Jan 24, 2012 at 2:02 PM, Ashish Goel wrote:
>
>
>
>
> struct node
> {
> int data;
> struct node *link;
> };
>
> node* CreateNode(int val)
> {
> node* root = (node*)malloc(sizeo
struct node
{
int data;
struct node *link;
};
node* CreateNode(int val)
{
node* root = (node*)malloc(sizeof(struct node));
root->data = val;
root->link = NULL;
return root;
}
node* createList(int *arr, int n)
{
node * root = CreateNode(arr[0
got it..thnx yr
On Tue, Oct 4, 2011 at 8:34 AM, rahul sharma wrote:
> so we shoul d aslo add loop at the top to find only for firrst row and
> column the initial values
>
>
> On Tue, Oct 4, 2011 at 8:30 AM, Ashish Goel wrote:
>
>> 0 in 0th row as well as 0 in 0th col and hence true
>>
>>
>> Best
so we shoul d aslo add loop at the top to find only for firrst row and
column the initial values
On Tue, Oct 4, 2011 at 8:30 AM, Ashish Goel wrote:
> 0 in 0th row as well as 0 in 0th col and hence true
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
>
0 in 0th row as well as 0 in 0th col and hence true
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Tue, Oct 4, 2011 at 8:28 AM, rahul sharma wrote:
> row0 and col0 initilayy true coz we have 0 in 0 row???or these r default
> values?
>
>
> On T
row0 and col0 initilayy true coz we have 0 in 0 row???or these r default
values?
On Tue, Oct 4, 2011 at 8:07 AM, Ashish Goel wrote:
> 1 1 0 1
> 0 1 1 1
> 1 1 1 1
> 1 1 1 0
>
> row0 is true
> col0 is true
>
> for (int i=1; i for (int j=1;j if (a[i][j] == 0) {a[i][0]=0; a[0][j]=0;}
>
> now after t
1 1 0 1
0 1 1 1
1 1 1 1
1 1 1 0
row0 is true
col0 is true
for (int i=1; iwrote:
> @ashish can u give an xample.plz...i have read a lot archives ...but
> cant find in 0(1) spaceu using 2 var only...plz give xample...nended
> urgent.thnx
>
>
> On Tue, Oct 4, 2011 at 7:26 AM, Ashish Goel w
@ashish can u give an xample.plz...i have read a lot archives ...but
cant find in 0(1) spaceu using 2 var only...plz give xample...nended
urgent.thnx
On Tue, Oct 4, 2011 at 7:26 AM, Ashish Goel wrote:
> keep two var row0 and col0 for checking if there is any 0 in row0flag
> /col0flag
>
>
keep two var row0 and col0 for checking if there is any 0 in row0flag
/col0flag
now walk over elements from 1,1 to n,m and set corresponding entry in 0th
row /column if you hit a zero.
now walk over zeroth column and rwo and set the complete row/col if a 0 is
there in 0th row/col.
after this bas
yeah it is wrong..i have a solution but uses 0(n+m) space.i need it
in 0(n*m) tymand o(1) space
On Mon, Oct 3, 2011 at 11:55 AM, shady wrote:
> search archives :-/
>
>
> On Mon, Oct 3, 2011 at 11:47 AM, pranav agrawal <
> pranav.is.cool.agra...@gmail.com> wrote:
>
>> @rahul sharma, i ran
search archives :-/
On Mon, Oct 3, 2011 at 11:47 AM, pranav agrawal <
pranav.is.cool.agra...@gmail.com> wrote:
> @rahul sharma, i ran this code, it is producing wrong answer :|
>
> check it, http://codepad.org/THv1hJq1
>
> anyone with correct solution?
>
> --
> You received this message because
*@all to median of BST time O(n) space O(1) (modified code of nitin to
get median)
medianBST*(node, n)
int x = 0;
*while* hasleftchild(node) *do*
node = node.left
*do*
x++;
if (x == n/2) return node->val;
*if* (hasrightchild(node)) *then*
node = node.right
*whil
Since we are given pointer to root node, we can easily find the minimum
element in the tree.
This will be the first node in the inorder traversal, now use method to find
the inorder successor of a each node. Do it iteratively.
Complexity will be O(n log n) and O(n) if tree is skewed.
Correct me
Do inorder traversal, to find out the total no. of nodes.
Next time, do the inorder traversal but keeping the count of nodes visited
and stop when you visit n/2 nodes.
Non recursive In-order Traversal -
*inorder*(node)
*while* hasleftchild(node) *do*
node = node.left
*do*
visit(node)
Recursion also requires space, so the problem is how to traverse without
extra space.
Once this is done, nothing is left in the problem.
Sanju
:)
On Tue, Sep 27, 2011 at 8:35 AM, Dheeraj Sharma wrote:
> @anshu
> can middle element can be found if the no. of nodes are not given...
>
>
> On Tue
@anshu
can middle element can be found if the no. of nodes are not given...
On Tue, Sep 27, 2011 at 8:34 PM, vikas wrote:
> a simple one is rabit-tortoise method, and using stackless traversal,
> facing a lot of corner cases in coding this, can someone check this as
> well?
>
> On Sep 27, 6:41 p
its not o(n) it is O(max height of tree) :P
i have not seen the constraint.
--
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
algoge
Suppose matrix is
1 0 0 1
1 0 1 0
0 0 0 0
then we traverse the matrix for each 1 we found at a[i][j] , we will check
for i=i to i wrote:
> If you're given that it's a sparse matrix, then you must assume
> storage is in a sparse matrix data structure to get time less than
> O(mn).
>
> In fact, if
Guys an Update ,
This has been asked in MS by me.. I suggested O(m*n) but they were looking
for a solution in nlogn ( n*n Sparse Matrix ) ..Any idea ...
This post was discussed earlier but every1 came with O(m*n) solution so
instead of cluttering it ..opened a new One ...
On Tue, Sep 27, 2011
i made a boo boo
--
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...@googlegroups.com.
For more options, visit t
@shrey but its not given in question that we have to return the position
or the occurence in the document.. we hav to only the tell whether the word
is in document..
read
.design a code which efficiently search the word and find occurrence of it
in given document .
its nt given that return the
ohh sry my mistake .. got it
On Thu, Aug 25, 2011 at 7:36 PM, Shrey Choudhary wrote:
> "design a code which efficiently search
> the word and find occurrence of it in given document"
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group
no ..
question says that there is a function that gives the next word in the
document..
this means after hashing one word , we hav to go to another word ... for
this going to next word in the document , we hav already provided wid a
function..
nothing to do wid the occurence
On Thu, Aug 25, 201
for every word in the document , apply hash funtion.. store the string n
its frequency too..
if we get the same word , then increment the frequency.
after storing.
whenver we want to search the word , searching in O(1) time , jst applying
hash function again on the word to be searched ..
corre
ya why not hashing ?
On Thu, Aug 25, 2011 at 3:31 PM, SANDEEP CHUGH wrote:
> wat abt doing wid hashing?
>
>
> On Thu, Aug 25, 2011 at 3:55 PM, vikas wrote:
>
>> yep, trie needs to be built
>>
>> On Aug 24, 10:49 pm, Ankur Garg wrote:
>> > It means when u call that func u get the next word in the
wat abt doing wid hashing?
On Thu, Aug 25, 2011 at 3:55 PM, vikas wrote:
> yep, trie needs to be built
>
> On Aug 24, 10:49 pm, Ankur Garg wrote:
> > It means when u call that func u get the next word in the document
> >
> > Regards
> > Ankur
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Aug 24, 2011
It means when u call that func u get the next word in the document
Regards
Ankur
On Wed, Aug 24, 2011 at 6:59 PM, vikas wrote:
> what do you mean by "a function for finding the next word is given" ?
>
> On Aug 22, 1:56 am, Ankur Garg wrote:
> > Question--> Given a document containing some
Below is a solution -
#include
int main(int argc, char* argv[]){
int i = 0;
char *array = argv[1];
char prev = array[0];
while(array[i]){
int count = 0;
while(prev == array[i]){
i +=1;
@gopi.. didnt got you...
@adi.. ya thats what i am talking about...
Regards,
Priyanshu Gupta
On Tue, Aug 9, 2011 at 11:18 AM, Aditya Virmani wrote:
> i guess ur qn was how will u decide which frame shud b ur thumbnail...as
> after tht, the frame cud be set as a thumbnail which is pretty much
i guess ur qn was how will u decide which frame shud b ur thumbnail...as
after tht, the frame cud be set as a thumbnail which is pretty much an eay
task in windows programming.i think most, dun hav much info abt it though,
thumbnails shud contain more of data; i mean shudnt be unicolour(blank
scree
I guess , it can be done using indexing , with time stamp as key , and frame
pointer as data ..
Please correct me if I am wrong.
On Tue, Aug 9, 2011 at 11:03 PM, Priyanshu wrote:
> Anyone??
>
> Regards,
> Priyanshu Gupta
>
>
> On Fri, Aug 5, 2011 at 6:09 PM, priyanshu wrote:
>
>> Give an efficie
Test cases for MSN Search Engine
1 : Check for auto completion feature (The auto completion based on the
prefix should provide suggestions for the most searched keyword with that
prefix)
.
2 : The spelling correction feature which shows as to what the user
actually meant. This should be highly
what has palindrome to do with this?
On Mon, Jul 18, 2011 at 1:11 AM, swetha rahul wrote:
> Thanks everyone!!
>
>
> On Sun, Jul 17, 2011 at 10:56 PM, ankit sambyal wrote:
>
>> Check for case senstivity also:
>> eg: "Madam" and "madam" both are palindromes.
>>
>>
>> Also for clarify with the int
Thanks everyone!!
On Sun, Jul 17, 2011 at 10:56 PM, ankit sambyal wrote:
> Check for case senstivity also:
> eg: "Madam" and "madam" both are palindromes.
>
>
> Also for clarify with the interviewer whether whitespace and
> punctuation can be ignored.
> eg: is the following string a palindrome
Check for case senstivity also:
eg: "Madam" and "madam" both are palindromes.
Also for clarify with the interviewer whether whitespace and
punctuation can be ignored.
eg: is the following string a palindrome or not:
"A man, a plan, a canal, Panama"
And check for this condition accordingly
--
check for query injection,string like (spaces,nothing) entered.
On Sun, Jul 17, 2011 at 9:04 PM, Dumanshu wrote:
> Well, for the third case, you can elaborate on the implementation. We
> need to compare the first half with the later half. So, in case of
> even no. of characters it splits perfect
is this ans sufficient..? any other possible test cases for palindrome ?
On Sun, Jul 17, 2011 at 8:53 PM, Nishant wrote:
> 1.If string is NULL then it should return 1 i.e. string is palindrome
> 2.If there is only one character in string then it is palindrome
> 3.If reverse of given string is sa
Sorry dave, your solution works.
Thanks for the answer, What I was assuming to be a Counting sort was a
variant of it
for integers.
On Thu, Jun 30, 2011 at 7:56 AM, Dave wrote:
> @Rizwan: I don't see the problem. Initialize an array of counters, one
> for each possible last character, to zero. I
@Dave: Think of it again counting sort won't work, If you are just
considering the last character as
the even though key is just last character, the value is the whole string..
On Tue, Jun 28, 2011 at 1:53 PM, juver++ wrote:
> List[letter] - linked list of all words with the last character as l
List[letter] - linked list of all words with the last character as letter.
Then iterate over all letters and concatenate lists.
--
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.co
@Dave:can u please explain the second method.
On Mon, Jun 27, 2011 at 11:24 PM, Dave wrote:
> @Nishant: Here are a couple of O(n) alternatives, given that there are
> a limited number of "last characters" and no requirement to break ties
> in any particular way:
>
> 1. A counting sort.
>
> 2. Fo
Nice Confusion... :)
Consider the following case
A[M] = {1,1,3,12};
B[N] = {1,2,12}
here again i think answer should be {1,1,12} , why are u binding one
occurrence of 1 in array A with one in B. Question is which elements of
first array is present in second array. so for this case A[0], A[1], A[
i meant if N = { 1, 1, 1, 2, 12}
and M = { 1, 1, 3, 12}
then answer should be = {1, 1, 12}
On Mon, Jun 13, 2011 at 8:06 PM, sunny agrawal wrote:
> no we can take care of duplicates without any extra memory
> modify 2nd step of my previous solution as follows
>
> if T[a[i]] is set then this eleme
Good one! That halved the memory requirement. :)
--
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/-/N6mbMaJHO64J.
To post to this group, send email to algogeek
no we can take care of duplicates without any extra memory
modify 2nd step of my previous solution as follows
if T[a[i]] is set then this element is there in second array so report this
element and Reset T[a[i]].
now no duplicates will be reported. and only 1025 bits will be required.
any failure
we can take care of the duplicate entries, but then that would cost more
space(int), as of now we are working with bool
On Mon, Jun 13, 2011 at 5:51 PM, sunny agrawal wrote:
> that will report duplicate entries multiple times :(
>
>
> On Mon, Jun 13, 2011 at 5:38 PM, sunny agrawal wrote:
>
>> why
that will report duplicate entries multiple times :(
On Mon, Jun 13, 2011 at 5:38 PM, sunny agrawal wrote:
> why do we need 2 bits at all ??
> i think single bit per table entry will do.
> say table is T[1025], and array is A[M]
>
>
> 1. Go through the N sized array and set bit 0 of the hash tabl
why do we need 2 bits at all ??
i think single bit per table entry will do.
say table is T[1025], and array is A[M]
1. Go through the N sized array and set bit 0 of the hash table entry to 1
if it is present in the first array.
2. Go through the M sized array and if T[a[i]] is set then this elemen
66 matches
Mail list logo