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.
int n = 1000001;
Map<Integer, Integer> map = new HashMap<>();
for (int a = 0; a < n; a++) map.put(a,a);
for (int i = 2; i < n; i++) {
if (map.get(i) > map.get(i - 1) + 1) {
map.put(i, map.get(i - 1) + 1);
}
for (int j = 2; j <= i && j * i < n; j++) {
if (map.get(i * j) > map.get(i) + 1) {
map.put(i * j, map.get(i) + 1);
}
}
}
I followed @Dimitark alg, but I used map. Since I use it for my other solution (division). Alsp, I think mine had better time complexity since I omited some conditions and lines. But it still runtime error.
Can someone help me out here?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Down to Zero II
You are viewing a single comment's thread. Return to all comments →
Can someone reviewed my code.
Can someone help me out here?