Have a look into this
https://leetcode.com/discuss/interview-question/1529612/Very-Very-Imp-Question-This-is-being-asked-in-many-companies-and-in-future-also-it-will-come.
Codeforces Round 937 Div 4 Solution Discussion (with myself) + Answering Your Questions