+ 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
44 Respuestas
+ 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.
+ 6
@Rakowiecki: Hope this helps
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map
+ 5
I added up all the elements in each and subtracted one from the other.. ooooo you got me all sorts of curious now
+ 5
😉
+ 4
lol, levels are just time.. they do not reflect skill 😊
+ 3
Bookmarked for when it isnt 2:30am :)
+ 3
Is there only one number missing? or multiple numbers?
+ 3
is mine ok?..
edit: not typing out a full array cause yeah..
+ 3
Got me stumped 😀
+ 3
Updated my code answer.. taking foooorever to save
+ 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;
}
+ 3
math lol 😁
+ 3
go for your swim. that was good, learned two different ways of doing this thanks to you!
+ 2
Could you explain how your code works step by step?
+ 2
I do not know js
+ 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])
+ 1
without a loop:) without if :) this is slow there is a faster way
+ 1
only 1