educative.io

Time complexity for Most Stones Removed

The stated time complexity of the solution is O(nlogn), where n is the number of stones and logn is the time taken by a union-find. If we use path compression and ranking, does the union-find take O(logn), or O(α(n)) which simplifies to O(1)? From an earlier Union Find problem: “The time complexity of the the Union and Find functions is O(α(n)), since both path compression and union find by rank are being used. α(n) is almost constant time and grows very slowly with the input size, so the time complexity of both these functions can be considered as constant time for practical purposes.”


Course: Grokking Coding Interview Patterns in Python - AI-Powered Learning for Developers
Lesson: https://www.educative.io/courses/grokking-coding-interview-patterns-python/solution-most-stones-removed-with-same-row-or-column