A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y).

Given a starting point (sx, sy) and a target point (tx, ty), return True if and only if a sequence of moves exists to transform the point (sx, sy) to (tx, ty). Otherwise, return False.


Examples:
Input: sx = 1, sy = 1, tx = 3, ty = 5
Output: True
Explanation:
One series of moves that transforms the starting point to the target is:
(1, 1) -> (1, 2)
(1, 2) -> (3, 2)
(3, 2) -> (3, 5)

Input: sx = 1, sy = 1, tx = 2, ty = 2
Output: False

Input: sx = 1, sy = 1, tx = 1, ty = 1
Output: True



Note:


       sx, sy, tx, ty will all be integers in the range [1, 10^9].

Source: leetcode | Difficulty: MEDIUM_HARD
Tags: Mathematics

Starter code: class Solution:
    def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:
        

Solutions:
class Solution:

	def maxChunksToSorted(self, arr):
		(cnt, sm, ism) = (0, 0, 0)
		for (i, num) in enumerate(arr):
			sm += num
			ism += i
			if sm == ism:
				cnt += 1
		return cnt


class Solution:

	def maxChunksToSorted(self, arr):
		max = 0
		rtype = 0
		for i in range(0, len(arr)):
			if arr[i] > max:
				max = arr[i]
			if max == i:
				rtype = rtype + 1
		return rtype


class Solution:

	def maxChunksToSorted(self, a):
		(max_seen, total_seen, res_count) = (0, 0, 0)
		for num in a:
			max_seen = max(max_seen, num)
			total_seen += 1
			if max_seen == total_seen - 1:
				res_count += 1
		return res_count


class Solution:

	def maxChunksToSorted(self, arr):
		cnt = 0
		max_curr = -1
		for i in range(len(arr)):
			max_curr = max(max_curr, arr[i])
			if max_curr == i:
				cnt += 1
		return cnt


class Solution:

	def maxChunksToSorted(self, arr):
		(maxx, chunkCount) = (0, 0)
		for i in range(len(arr)):
			maxx = max(maxx, arr[i])
			if i >= maxx:
				chunkCount += 1
		return chunkCount


class Solution:

	def maxChunksToSorted(self, arr):
		if not arr:
			return 0
		res = 0
		l = len(arr)
		curr = -1
		flag = False
		for i in range(l):
			c = arr[i]
			if flag:
				curr = max(curr, c)
				if curr == i:
					curr = -1
					res += 1
					flag = False
			elif c == i:
				res += 1
			else:
				curr = max(curr, c)
				flag = True
		return res


class Solution:

	def maxChunksToSorted(self, arr):
		chunks = 0
		max_this_chunk = 0
		for (index, num) in enumerate(arr):
			if num > max_this_chunk:
				max_this_chunk = num
			if max_this_chunk <= index:
				chunks += 1
				max_this_chunk = 0
		return chunks


class Solution:

	def maxChunksToSorted(self, arr):
		m = -1
		ans = 0
		for (i, num) in enumerate(arr):
			m = max(num, m)
			if m == i:
				ans += 1
		return ans


class Solution:

	def maxChunksToSorted(self, arr):
		total_chunks = 0
		max_so_far = 0
		for (i, val) in enumerate(arr):
			max_so_far = max(max_so_far, val)
			if max_so_far == i:
				total_chunks += 1
		return total_chunks


class Solution:

	def maxChunksToSorted(self, arr):
		res = 0
		cur = arr[0]
		for (i, v) in enumerate(arr):
			if v > cur:
				cur = v
			if i == cur:
				res += 1
		return res