Re: [algogeeks] Give Algo to do this in O(n)

2011-10-10 Thread anubhav gupta
 @deoki try for 1001,999,998,1

On Mon, Oct 10, 2011 at 6:57 PM, Deoki Nandan  wrote:

> just find minimum and secon minimum by taking two variables in O(n)
>
> On 10 October 2011 17:57, sandeep nagamalli  wrote:
>
>> @Shiva: How can min heap be uesd, can you eloborate a bit.
>>
>> As far as i see, the best possible is O(nlogn) i.e by sorting and scanning
>> over the complete array once.
>>
>>
>>
>>
>> On Mon, Oct 10, 2011 at 9:49 AM, shiva@Algo wrote:
>>
>>> I think Min heap will do that..
>>>
>>>
>>> On Mon, Oct 10, 2011 at 12:37 AM, Ankur Garg wrote:
>>>
 Given an unsorted array of Integers

 Find 2 nos whose diff is minimum

 Say Array is  4 2 18 19 11 8 5

 Nos are 18 and 19

 Algo shud be of O(n)

 --
 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 this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>  --
>>> 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 this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Thanks&Regards:
>> -sandeep
>>
>>
>>  --
>> 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 this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> **With Regards
> Deoki Nandan Vishwakarma
> IIT ROORKEE
> 9760340784
> for Computer Science Interview Material see my home page
> https://sites.google.com/site/deokinandanmaterials/
>
> *
> *
>
>  --
> 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 this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] First non-repeated character complexity?

2011-09-28 Thread anubhav gupta
http://ideone.com/tJPjL

On Thu, Sep 29, 2011 at 10:11 AM, saurabh singh  wrote:

> http://www.ideone.com/tY7jM
>
> On Wed, Sep 28, 2011 at 8:13 PM, sreeprasad.sp wrote:
>
>>
>>
>>  public class firstNonRepeatedCharInString {
>>
>> public static void main(String abc[]){
>>
>> firstNonRepeatedCharInString f = new firstNonRepeatedCharInString();
>> String checkString="bbzbccdede";
>> String checkString1="bzzccde";
>> String checkString2="abcdef";
>> String checkString3="aabc";
>> String checkString4="zzcc";
>> int index=f.getIndexOfFirstNonRepeatingChar(checkString);
>> if(index!=-1)
>> System.out.println("the first non repeating character in "
>> +checkString +" is at "+checkString.charAt(index));
>> else
>> System.out.println("there is no repeating character in " +checkString
>> );
>>
>>  index=f.getIndexOfFirstNonRepeatingChar(checkString1);
>> if(index!=-1){
>> System.out.println("the first non repeating character in "
>> +checkString1 +" is at "+checkString1.charAt(index));
>> }else
>> System.out.println("there is no repeating character in "
>> +checkString1 );
>>
>>
>>  index=f.getIndexOfFirstNonRepeatingChar(checkString2);
>> if(index!=-1)
>> System.out.println("the first non repeating character in "
>> +checkString2 +" is at "+checkString2.charAt(index));
>> else
>> System.out.println("there is no repeating character in " +checkString2
>> );
>>
>>  index=f.getIndexOfFirstNonRepeatingChar(checkString3);
>> if(index!=-1)
>> System.out.println("the first non repeating character in "
>> +checkString3 +" is at "+checkString3.charAt(index));
>> else
>> System.out.println("there is no repeating character in " +checkString3 );
>>
>>  index=f.getIndexOfFirstNonRepeatingChar(checkString4);
>> if(index!=-1)
>> System.out.println("the first non repeating character in "
>> +checkString4 +" is at "+checkString4.charAt(index));
>> else
>> System.out.println("there is no repeating character in " +checkString4
>> );
>> }
>>
>> public int getIndexOfFirstNonRepeatingChar(String checkString){
>>   char [] toCharArray = checkString.toCharArray();
>> if(toCharArray.length==1)
>> return 0;
>> else if(toCharArray.length==2) {
>> if(toCharArray[0]==toCharArray[1]) return -1;
>> }else if(toCharArray.length==3){
>> if (((checkString.charAt(0))!=(checkString.charAt(1))) &&
>> (checkString.charAt(1) != checkString.charAt(2))){
>> return 0;
>> }else if((checkString.charAt(0)==checkString.charAt(1)) &&
>> (checkString.charAt(1)!=checkString.charAt(2))){
>>  return 2;
>> }else if( (checkString.charAt(0)!=checkString.charAt(1)) &&
>> (checkString.charAt(1)==checkString.charAt(2)))
>> return 0;
>> }
>>
>>
>> else{
>>  for(int i=0;i> if (((checkString.charAt(i))!=(checkString.charAt(i+1))) &&
>> (checkString.charAt(i+1) != checkString.charAt(i+2))){
>>   return i;
>> }else if( (checkString.charAt(i) != checkString.charAt(i+1))
>> && (checkString.charAt(i+1)==checkString.charAt(i+2))){
>> if(i-1<0){
>>return i;
>> }else{
>>
>>
>> if( (checkString.charAt(i-1)==(checkString.charAt(i))) &&
>> (checkString.charAt(i+1)==checkString.charAt(i+2)))
>>  continue;
>>   else
>> return i;}
>>
>> }else if( (checkString.charAt(i)== checkString.charAt(i+1)) &&
>> (checkString.charAt(i+1)!=checkString.charAt(i+2))){
>> if( (i+3)<=checkString.length() ){
>> if(checkString.charAt(i+2)!=checkString.charAt(i+3)){
>> return i+2;
>> }else{
>> continue;
>> }
>>
>> }else {return i+2;}}
>> }
>> }
>>
>>  return -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/-/AgtYjYsCg1UJ.
>>
>> 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 this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT ALLAHABAD
>
>
>
>  --
> 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 this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.

Re: [algogeeks] Puzzle

2011-08-04 Thread anubhav gupta
both ropes have to burn in one hour.. so if burn first rope at both ends it
wil definitely take 30 mins to burn completely no matter how non uniform
burning is.. when first rope burn out completly(after 30 mins) second rope
still have 30 mins left for complete burning so if  it is burn at both ends
it wil take half the time left i.e 15 mins .. so in total we get 45 mins

On Thu, Aug 4, 2011 at 4:32 PM, Nikhil Gupta wrote:

> @priyanka, the ropes have a non uniform rate of burning. Means at some
> duration they will be burning faster, and slower at some. So you cannot say
> that  first rope will take 30mins to burn completely, and by that time
> second rope is half burnt.
>
>>
>>>
>>> Nikhil Gupta
>
>  --
> 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 this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] aptitude

2011-08-03 Thread anubhav gupta
16.. 61 ... 106
ans shld be 45 mile/hr

On Wed, Aug 3, 2011 at 7:14 PM, Kamakshii Aggarwal wrote:

> vaibhav can u please explain.i know the answer already..i m just not able
> to solve the equations fully
>
>
> On Wed, Aug 3, 2011 at 7:09 PM, Arun Vishwanathan 
> wrote:
>
>> in general, if u guys get any answer, please post a short explanation even
>> if it the solution is very obvious to u...not everyone gets it when looking
>> at the answer...
>>
>>
>> On Wed, Aug 3, 2011 at 3:34 PM,  wrote:
>>
>>> 45 km/hr
>>>
>>> VM
>>> NSIT, COE, 3rd year
>>>
>>>
>>> On , Kamakshii Aggarwal  wrote:
>>> > A car is traveling at a uniform speed.The driver sees a milestone
>>> showing a 2-digit number. After traveling for an hour the driver sees
>>> another milestone with the same digits in reverse order.After another hour
>>> the driver sees another milestone containing the same two digits. What is
>>> the average speed of the driver?
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> >
>>> > 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 this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>> >
>>> >
>>> >
>>> >
>>>
>>> --
>>> 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 this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>>
>>  --
>> 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 this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards,
> Kamakshi
> kamakshi...@gmail.com
>
>  --
> 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 this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Coing tossing(SPOJ)

2011-06-28 Thread anubhav gupta
http://www.se.cuhk.edu.hk/~seem3570/12-pattern.pdf

On Tue, Jun 28, 2011 at 5:26 PM, Nitish Garg wrote:

> Hey
> The question I am currently working on is
> http://www.spoj.pl/problems/MAIN8_D/
> Actually I am unable to understand how the answer for HTHT is 20. I know
> that the worst case for a string of 4 coin tosses should be 16*4. But how
> the expected value is 20?
> Can anyone explain?
> Thanks
>
> --
> 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/-/DFckKu4bb-0J.
> 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 this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 this group at 
http://groups.google.com/group/algogeeks?hl=en.