We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Journey to the Moon
Journey to the Moon
Sort by
recency
|
514 Discussions
|
Please Login in order to post a comment
You can always use a long long type in C++.
Has anyone successfully passed test case 11
100000 2
1 2
3 4
expected ans : 4999949998
the expected output is 4,999,949,998, which exceeds the 32-bit integer limit (2,147,483,647). This seems to cause overflow in languages where int is 32-bit by default.
Test case 11 doesn't work with the function signature in rust. The answer is > i32::MAX.
For python code, test case 11, if you use summation over and over for calculating the final results, you could use cummulative sum to avoid it. it will help you to speed up.
Runtime error on #11 testcase others are successfully executed
int parent[100001]; int Size[100001];
void make(int n){ for(int i=0;i
int find(int vertex){ if(parent[vertex]==vertex)return vertex; return parent[vertex]=find(parent[vertex]); }
void Union(int a,int b){ a=find(a); b=find(b); if(a==b)return ; if(Size[b]>Size[a])swap(a,b); parent[b]=a; Size[a]+=Size[b]; }
int journeyToMoon(int n, vector> astronaut) { make(n);