Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- '''
- Author: Shakib Haris
- Problem: Maximum Subarray Problem
- Input: The Price(s), not the Change(s)
- Output: Maximum Subarray
- '''
- def bruteForce (A):
- maxDif = A[1] - A[0]
- lenA = len(A)
- for buy in range (lenA - 1):
- for sell in range (buy + 1, lenA):
- diff = A[sell] - A[buy]
- if diff > maxDif:
- start, end, maxdif = buy, sell, diff
- return start, end
- def display (A):
- for item in A:
- print ("%d " %(item), end = "")
- print ("")
- A = [int(x) for x in input().split()]
- print("Original Array: ", end = "")
- display(A)
- start, end = bruteForce(A)
- print("Sub-array: ", end = "")
- display(A[start:end + 1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement