Re: repeating elements in an array
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Mon, 05 Apr 2010 21:57:39 +0100
mohangupta13 wrote:
hello all,
Hope everyone is in the pink of perfection ! ...i was out for a long
time i think ..
anyway i had two problems to discuss ...
1. Given an array in which only one pair of number ( say integers ) is
repeating ,all other numbers are distinct ..what is the best possible
algo to find such number ..?? ( say for both cases when we dont have
any constraint on the numbers and when we do define some constrain say
the range of possible numbers in the array)...
Lacking a definition of "best", the simplest way is to sort the array, and then iterate through it looking for adjacent elements with the same value.
2. (this may not be suited here but still ) What is the probability
that out of 5 persons, no two person have birthday on the same day of
a week (..i.e all 5 have birthdays on different days of a week)..???
7! / (7-5)!
-----------
5
7
= 7 * 6 * 5 * 4 * 3
-----------------
7 * 7 * 7 * 7 * 7
= 360/2401, or slightly over 0.14993752603.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
.
- Follow-Ups:
- Re: repeating elements in an array
- From: mohangupta13
- Re: repeating elements in an array
- References:
- repeating elements in an array
- From: mohangupta13
- repeating elements in an array
- Prev by Date: Re: repeating elements in an array
- Next by Date: "Variable Depth" Problem
- Previous by thread: Re: repeating elements in an array
- Next by thread: Re: repeating elements in an array
- Index(es):
Relevant Pages
|