diff --git a/src/my_project/interviews/amazon_high_frequency_23/round_7/minimum_number_of_operations_to_turn_array_into_a_palindrom.py b/src/my_project/interviews/amazon_high_frequency_23/round_7/minimum_number_of_operations_to_turn_array_into_a_palindrom.py new file mode 100644 index 00000000..fa9a98f0 --- /dev/null +++ b/src/my_project/interviews/amazon_high_frequency_23/round_7/minimum_number_of_operations_to_turn_array_into_a_palindrom.py @@ -0,0 +1,28 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def minimumOperations(self, nums: List[int]) -> int: + + l, r = 0, len(nums) - 1 + ls = nums[l] + rs = nums[r] + answer = 0 + + while l < r: + + if ls == rs: + l += 1 + r -= 1 + ls = nums[l] + rs = nums[r] + elif ls < rs: + l += 1 + ls += nums[l] + answer += 1 + else: + r -= 1 + rs += nums[r] + answer += 1 + + return answer \ No newline at end of file