Re: [algogeeks] do this: two numbers with min diff

2010-09-23 Thread Nishant Agarwal
int minDiff(int arr[], int arr_size)
{
  int min_diff = arr[1] - arr[0];
  int max_element = arr[0];
  int i;
  for(i = 1; i  arr_size; i++)
  {
if(arr[i] - max_element  min_diff)
  min_diff = arr[i] - max_element;
if(arr[i]  max_element)
 max_element = arr[i];
  }
  return min_diff;
}


On Mon, Sep 20, 2010 at 10:38 AM, Srinivas lavudyasrinivas0...@gmail.comwrote:

 2 nos with min diff
 given an array of size n. find 2 numbers from array whose difference
 is least in O(n) w/o
 using xtra space( i mean constant space)

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
 :-)
*
Nishant Agarwal
Computer Science and Engineering
NIT Allahabad
*

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



[algogeeks] do this: two numbers with min diff

2010-09-19 Thread Srinivas
2 nos with min diff
given an array of size n. find 2 numbers from array whose difference
is least in O(n) w/o
using xtra space( i mean constant space)

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