+ 3

How to find which Number is missing in a 100 Numbers array without using loops .Find The fastest way. Prove your method.

1,2,3.....□,45,46,....100

30th Jun 2017, 4:01 PM
Rakowiecki Ryszard
Rakowiecki Ryszard - avatar
44 Réponses
+ 2
@Rakowiecki You are right. The array prototype functions is powerful. If you interested on more information, you should check out the function of "map, filter and includes" in developer.mozilla.org site . Jay has shared the link. Thanks @jay.
1st Jul 2017, 1:23 AM
Calviղ
Calviղ - avatar
1st Jul 2017, 12:52 AM
jay
jay - avatar
+ 5
I added up all the elements in each and subtracted one from the other.. ooooo you got me all sorts of curious now
30th Jun 2017, 4:37 PM
jay
jay - avatar
+ 5
😉
30th Jun 2017, 5:17 PM
jay
jay - avatar
+ 4
lol, levels are just time.. they do not reflect skill 😊
30th Jun 2017, 4:38 PM
jay
jay - avatar
+ 3
Bookmarked for when it isnt 2:30am :)
30th Jun 2017, 4:14 PM
jay
jay - avatar
+ 3
Is there only one number missing? or multiple numbers?
30th Jun 2017, 4:21 PM
jay
jay - avatar
+ 3
is mine ok?.. edit: not typing out a full array cause yeah..
30th Jun 2017, 4:33 PM
jay
jay - avatar
+ 3
Got me stumped 😀
30th Jun 2017, 4:35 PM
jay
jay - avatar
+ 3
Updated my code answer.. taking foooorever to save
30th Jun 2017, 5:01 PM
jay
jay - avatar
+ 3
#include <iostream> #include <array> #include <numeric> int main() { std::array<int, 4> arr = { 1, 2, 4, 5 }; int max = arr.back(); int min = arr.front(); int sum = std::accumulate(arr.begin(), arr.end(), 0); int actual = (((max*(max + 1)) / 2) - min + 1); std::cout << actual - sum; }
30th Jun 2017, 5:04 PM
jay
jay - avatar
+ 3
math lol 😁
30th Jun 2017, 5:07 PM
jay
jay - avatar
+ 3
go for your swim. that was good, learned two different ways of doing this thanks to you!
30th Jun 2017, 5:13 PM
jay
jay - avatar
+ 2
Could you explain how your code works step by step?
1st Jul 2017, 12:22 AM
Rakowiecki Ryszard
Rakowiecki Ryszard - avatar
+ 2
I do not know js
1st Jul 2017, 12:24 AM
Rakowiecki Ryszard
Rakowiecki Ryszard - avatar
+ 1
You didn't specify a language. In Python, this will tell you all numbers missing from an array between the lowest number and highest number nums=[1,3,5,7,9,11] hi=max(nums) low=min(nums) print([i for i in range(low,hi) if i not in nums])
30th Jun 2017, 4:16 PM
LordHill
LordHill - avatar
+ 1
without a loop:) without if :) this is slow there is a faster way
30th Jun 2017, 4:18 PM
Rakowiecki Ryszard
Rakowiecki Ryszard - avatar
+ 1
only 1
30th Jun 2017, 4:22 PM
Rakowiecki Ryszard
Rakowiecki Ryszard - avatar
30th Jun 2017, 4:31 PM
LordHill
LordHill - avatar