s="Hello HOw you are Doing Today" s1="goa" a="123nk" m=" " k=",,,..mks..orange" t="r\ti\tg\th\tt" print(s.capitalize()) print(s.casefold()) print(s.center(50,"0")) print(s.count("o")) print(s.endswith("Today")) print(t.expandtabs(3)) print(s.find("o"))#returns -1 if not present print(s.index("o"))#returns exception if not present print(a.isalnum())# returns true for [a-z] [0-9] print(a.isalpha()) print(a.isdigit())#return true for decimals,superscripts and false for fractions print(a.isdecimal())#return true for decimals and false for fractions ,superscripts print(a.isidentifier()) #should start with [a-z] [0-9] or _ , false for space ("my room") print(s.islower()) print(s.isnumeric())#return true for decimals,superscripts fractions print(m.isspace()) print(s.istitle())#Hi Ram What Happened print(s.isupper()) print(" ".join(["i","Love"...
Find the contiguous subarray within an array, A of length N which has the largest sum . Input Format: The first and the only argument contains an integer array, A. Output Format: Return an integer representing the maximum possible sum of the contiguous subarray. Constraints: 1 <= N <= 1e6 -1000 <= A[i] <= 1000 For example: Input 1: A = [1, 2, 3, 4, -10] Output 1: 10 Explanation 1: The subarray [1, 2, 3, 4] has the maximum possible sum of 10. Input 2: A = [-2, 1, -3, 4, -1, 2, 1, -5, 4] Output 2: 6 Explanation 2: The subarray [4,-1,2,1] has the maximum possible sum of 6. Solution: we can use Kadane's Algo O(n) | O(1) class Solution: # @param A : tuple of integers # @return an integer def maxSubArray(self, A): s=-(2**30) ans=0 for i in A: ...
Comments
Post a Comment