Data Structures, Algorithms, Leetcode, Segment Tree, Programming.
0x3f3f3f3f, prev = i; for(int j = i+1; j < 101; j++) if(mp[j] == 1) mi = min(mi, j - prev), prev = j; res.emplace_back(mi == 0x3f3f3f3f ? -1 : mi); } return res; } }; Hash table and binary search Another solution to this problem is to use a hash table to count the positions of each element that