@dave:
your code is producing 4526 for input=24526 instead of 2456
Here's corrected code :)
/CODE///
int function(int n){
int a[10]={0},temp=0,result =0;
while(n){ //reverse the number..
temp=10*temp+n%10;
n/=10;
}
n=temp;
while(n){
Hi all,
pls help me solve this problem..
Design an algorithm to find the majority element of an array..
majority element must be an element tht has the cardinality greater
than 2n/3 where n is the number of elements in the array and the time
complexity must be a linear time.. ie o(n)..
hint : use
If you can use both, it would be
head -10 foo | tail -6
It doesn't do the right thing if the file has fewer than 10 lines,
though.
Dave
On Sep 21, 4:04 pm, Divesh Dixit
wrote:
> How to get line no. 5 to line no. 10 only from a file.. using tail
> or head command.?
--
You received this mess
@Saurabh: Doesn't your code turn 123 into 321? Try this:
int function(int n)
{
int a[10]={0};
int result=0;
int place=1;
while(n){
if(a[n%10]==0){
a[n%10]=1;
result+=(n%10)*place;
place*=10;
}
n/=10;
}
return result;
}
Can anybody share his/her E-copy of An Introduction to algorithm by Udi
manber.It's a great resource.If anybody has please share his E-copy.Thanks
in advance.
--
Thanks & Regards
Nikhil Agarwal
Senior Undergraduate
Computer Science & Engineering,
National Institute Of Technology, Durgapur,India
h
high= const.(10^const)
What's const? The point of this isn't that it's a difficult prob to
solve. Point lies in working with the design to make this close to log
n.
Define what value "const" holds.
On Sep 21, 9:12 am, "coolfrog$"
wrote:
> its dictionary means shorted ordered arry.
> let low = 1
How to get line no. 5 to line no. 10 only from a file.. using tail
or head command.?
--
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
Sorry this doesn't work all grep out there ...
On 22 Sep, 01:40, Prem Mallappa wrote:
> @Neeraj:
> Your approach is good, this however lists .999.999.999 which is
> not a valid IP address.
>
> grep -lR "[0-255]\.[0-255]\.[0-255]\.[0-255]" *
>
> further filter out the output of above to invali
@Neeraj:
Your approach is good, this however lists .999.999.999 which is
not a valid IP address.
grep -lR "[0-255]\.[0-255]\.[0-255]\.[0-255]" *
further filter out the output of above to invalidate any ip address
that are reserved.
-l is for suppressing normal output and printing only filena
int function(int n){
int a[10]={0};
int result =0;
while(n){
if(a[n%10]==0){
a[n%10]=1;
result=10*result+n%10;
}
n/=10;
}
return result;`
}
On Wed, Sep 22, 2010 at 12:39 AM, Albert wrote:
> Given a number find the number by eliminating the duplicate digits in
> the
check this way of using list
#include
#include
#include
using namespace std;
struct node
{
int data;
struct node * rev;
};
int main()
{
struct node * pass,*start1,*store;
stack s1;
int i=1,carry=0,n,s;
printf("Enter");
scanf("%d",&n);
struct node * news=(struct node*)malloc(sizeof(struct node));
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.
Dave
On Sep 21, 1:16 pm, rajess wrote:
> find the volume of boxes as v=l*b*h
> sort boxes in volumes in descending or
Given a number find the number by eliminating the duplicate digits in
the number..
for eg: 24526 ans is 2456
.
int function(int n)
{
.
.
.
}
Give all sort of solutions to this problem.
Efficiency in the code is important
--
You received this message because you are subsc
find the volume of boxes as v=l*b*h
sort boxes in volumes in descending order and this is the way to
insert boxes one into another
On Sep 21, 7:55 pm, Rashmi Shrivastava wrote:
> If there are n number of boxes and each with different dimensions and your
> job is to insert one box having lesser di
1 followed by x zeros would be 2^x in base 2.
Dave
On Sep 21, 8:54 am, rajess wrote:
> why you can ,print a 1 followed by x number of zeros
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@goog
There is a 2 dimensional array with each cell containing a 0 or 1 ,
Design an algorithm to
find out which row has the maximum number of 1's , Your algorithm should
have O(n2)
time and no space complexity.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Ge
Guys!!
On Mon, Sep 20, 2010 at 7:08 PM, LG JAYARAM . wrote:
> @Krunal:
> can u explain hwz 7
>
>
> On Mon, Sep 20, 2010 at 6:02 PM, Krunal Modi wrote:
>
>> @LG JAYARAM:
>>
>> It is 7.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" g
its dictionary means shorted ordered arry.
let low = 1; and high= const.(10^const)
Boolean isWord(String word)
{ while(low <= high)
{ mid = (low+ high)/2;
if(word = getWordAt(mid))
return true;
if( word > getWordAt(mid))
Find area of Triangle(A) and area of Polygon with these four points(B)
if AB point lies inside triangle
else on if they are equal, it lies on triangle.
On Mon, Sep 20, 2010 at 10:39 PM, Nikhil Agarwal
wrote:
>
> Method 1:
> Yes you can do by writing equation of 3 lines taking 2 points at a time
instead of creating a bst why dontwe create a heap.then sort the heap .then
remove the duplictes from string...but will also chnge th order of
string.
On Sun, Sep 19, 2010 at 4:20 PM, Umer Farooq wrote:
> creating a bst would require extra space. You can do this with an array of
> char dude.
Guyswe need to find two numbers in a array with minimum difference ah
On Tue, Sep 21, 2010 at 8:52 PM, Rahul Singal wrote:
> try running it on [ 11 , 6 , 100, 101]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to
try running it on [ 11 , 6 , 100, 101]
--
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
What does [0-9]\+. means? Why do you nested it?
On Sep 21, 3:46 pm, Neeraj <17.neera...@gmail.com> wrote:
> *grep -R "\<[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+\>" * | awk -F':' '{print $1}' |
> uniq
> *
> works on my system :P
>
>
>
> On Tue, Sep 21, 2010 at 2:07 PM, Chi wrote:
> > With perl installed:
>
XOR all the elements from both arrays, the value that is left is x.
On Sep 20, 5:06 pm, Anand wrote:
> Two unsorted arrays are given A[n] and B[n+1]. Array A contains n integers
> and B contains n+1 integers of which n are same as in array B but in
> different order and one extra element x. Write
Consider you have a dictionary of unknown size. The size could be 10,
or 1000 or 10^30.
You are given a method- String GetWordAt(int index), which returns the
word at 'index',
or null if the index is invalid (or out of bounds).
How will you write a method that returns a boolean for a particular
wo
Find area of Triangle(A) and area of Polygon with these four points(B)
if AB point lies inside triangle
else on if they are equal, it lies on triangle.
On Tue, Sep 21, 2010 at 5:03 PM, jagadish wrote:
> Here is the Simplest working solution :)
>
> bool check(int x[],int y[],int n)
> {
> c=0;
>
*grep -R "\<[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+\>" * | awk -F':' '{print $1}' |
uniq
*
works on my system :P
On Tue, Sep 21, 2010 at 2:07 PM, Chi wrote:
> With perl installed:
>
> find directory | xargs perl -pi -e 's/needle/replace/g'
>
> With sed installed:
>
> #!/bin/bash
>
> find directory >
Method 1:
Yes you can do by writing equation of 3 lines taking 2 points at a time and
finding the sign with the third point.
Suppose: ax+by+c=0 is your first line and (x,y) is the third point then find
out the sign of the 3rd point satisfying it on the line. suppose this sign
is S (for +ve)
Simil
Trying to put down a method, I think would work ( with a small running
example )
//! Assuming non--negative numbers and difference is MOD of difference
of numbers
Let array be A[1..n]//! e.g. { 11 , 6 , 17 , 9 ]
Start with pari ( A[1], A[2] ) and difference be D = | A[1] - A[2]
|/// A[1]
grep /home/user/dir -d recurse -H \b(?:(?:25[0-5]|2[0-4][0-9]|[01]?
[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
the ugly looking block matches IP address. GREP is a gnu regex utility
in linux (also available for windows).
/home/user/dir is the location of the directory
-d recurse,
no need to addi all element if overflow is feared , subtract values
for given index in the loop
something like this
result = 0 ;
for(count = 0; count < n ;count ++){
result += (B[count]-A[count]);
}
result += B[count] ; //! this is the answer...
-Manish
On Sep 21, 9:44 am, Bal
If there are n number of boxes and each with different dimensions and your
job is to insert one box having lesser dimension than that to another.
Consider size of boxes as,
b1->s1(h1,l1,w1)
b2->s2(h2,l2,w2)
.
.
.
bn->sn(hn,ln,wn)
--
You received this message because you are subscribed to the Goog
void remove_duplicate(char * str)
{
if (*str == '\0')
return ;
else
{
char ch = *str;
char * temp ;
int i = 0 ;
while ( ch == *(str+i) )
{
i++;
}
if ( *(str+i) == '
do a preorder traversal,if you call the function put in stack,on
returning from the function delete the top element from the queue,if
find element return the queue.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send e
why you can ,print a 1 followed by x number of zeros
--
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...@googleg
solution 1:
use concept of quad-tree and do binary search in that tree
solution 2:
do binary search on major diagonal. ultimately u will narrow down to search
for element in 2 rows. in these two rows again do binary search.
any solution will lead you to O(log(n)) time
On Tue, Sep 21, 2010 at 5:
Hi all,
Given a 2d array which is sorted row wise and column wise as well,
find a specific element in it in LESS THAN O(n).
PS: an O(n) solution would involve skipping a column or a row each
time from the search and moving accordingly.
Solution less than O(n) is desirable!
--
You received this me
Here is the Simplest working solution :)
bool check(int x[],int y[],int n)
{
c=0;
for(int i=0;iy) != (y[j]>y)) && (x-x[i]/x[j]-x[i] < y-y[i]/y[j]-y[i])
c=!c;
}
return c;
}
On Sep 20, 7:46 pm, umesh kewat wrote:
> Initially we have given three point A , B, C in plane represent three nodes
> of
@Minotauraus: ur approach is flawed!
the BEST solution would be to use a maxheap as navin said! :)
On Sep 21, 1:55 pm, Naveen Agrawal wrote:
> @Minotauraus
>
> Your algo is wrong
> Consider this case:
> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
> 99 98 97 96 95 94 93 92
@Minotauraus
Your algo is wrong
Consider this case:
12 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80
According to your algo
1)Max for first window =99,i.e,curr max=99
2)Compare with new element,i.e wlth element numb
With perl installed:
find directory | xargs perl -pi -e 's/needle/replace/g'
With sed installed:
#!/bin/bash
find directory > mirror
exec 3 $file
done
On Sep 19, 11:30 pm, bittu wrote:
> Linux shell command to find all files in a directory which contain ip
> addresses
--
You received t
Thanks for clearing
On Tue, Sep 21, 2010 at 1:58 PM, Naveen Agrawal wrote:
>
> @Kartheek
>
> Ashish algo is perfectly workingBy making before[0]&after[length-1]=1
> the array is shifted ,which prevents the inclusion of current index.
>
> Ex:
>
> int a[5]={10,4,8,3,9}
>
> before[0]=1
> bef
@Kartheek
Ashish algo is perfectly workingBy making before[0]&after[length-1]=1
the array is shifted ,which prevents the inclusion of current index.
Ex:
int a[5]={10,4,8,3,9}
before[0]=1
before[1]=10
before[2]=40
before[3]=320
before[4]=960
after[4]=1
after[3]=9
after[2]=27
after[1]=21
You are correct ...It depends on the max element's index...
--
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+unsu
1)Sort the first 10 elements (first window)
2)initialise i=1,l=j=10
3)last element is the maximum(l=10) printf(a[l])
4)i=i+1,j=j+1 if(a[j]>a[l])
then printf(a[j])
l=j
5)else printf(a[l])
6)if(i==l)
repeat from step 1
for worst case it needs 10 sorts
Correct if i am wrong
--
You recei
45 matches
Mail list logo