Posts

LeetCode: Maximum SubArray

Question:-   https://leetcode.com/problems/maximum-subarray/ Soution:- class Solution :     def maxSubArray ( self , nums : List[ int ]) -> int :         maxsum = nums[ 0 ]         length_list = len (nums)         for index in range ( 0 ,length_list):             for nest_index in range (index,length_list):                 sel_sum = sum (nums[index:nest_index+ 1 ])                 if sel_sum>maxsum:                     maxsum = sel_sum         return maxsum This Solution PASSES 200 test case out of 210, need more optimization in terms of looping that we are using

LeetCode : Recyclable and Low Fat Products

Question: https://leetcode.com/problems/recyclable-and-low-fat-products/description/?envType=study-plan&id=sql-i Solution: # Write your MySQL query statement below select product_id from Products Where low_fats = 'Y' and recyclable = 'Y'

LeetCode: Jump Game

Question = https://leetcode.com/problems/jump-game/ Solution: class Solution :     def canJump ( self , nums : List[ int ]) -> bool :         n = len (nums)         reachable = 0         for i in range ( 0 ,n):             if reachable<i:                 return False             reachable = max (reachable,i+nums[i])         return True

LeetCode: Flip String to Monotone Increasing

Question:- https://leetcode.com/problems/flip-string-to-monotone-increasing/ Solution :-   class Solution: def minFlipsMonoIncr(self, s: str) -> int: len_s = len(s) zero_list = [0] one_list = [0] count_one = 0 count_two = 0 for i in range(1,len_s+1): if s[i-1]=='1': count_one+=1 one_list.append(count_one) for i in range(len_s,0,-1): if s[i-1]=='0': count_two+=1 zero_list.append(count_two) zero_list_new = list(reversed(zero_list)) flag=0 for i in range(0,len_s+1): sum1 = zero_list_new[i]+one_list[i] print(sum1) if flag==0: min_sum = sum1 flag=1 continue if sum1<min_sum: min_sum = sum1 print(zero_list_new) print(one_list) return min_sum Note:- The Code is not running prop...

Leetcode : Longest Valid Parameter

Question:https://leetcode.com/problems/longest-valid-parentheses/ Solution : class Solution :     def longestValidParentheses ( self , s : str ) -> int :         len_string = len (s)         count = 0         start_bracket = 0 ## (         for index in range ( 0 ,len_string):             if index== 0 :                 if s[index]== "(" :                     start_bracket += 1                 else :                     continue                         elif s[index] == "(" :                 if s[index- 1 ] == "(" :                     ...

Leetcode: JumpGameII

Question : https://leetcode.com/problems/jump-game-ii/description/ Solution :  class Solution : def jump ( self , nums ) : if len ( nums ) <= 1 : return 0 l , r = 0 , nums [ 0 ] times = 1 while r < len ( nums ) - 1 : times += 1 nxt = max ( i + nums [ i ] for i in range ( l + 1 , r + 1 ) ) l , r = r , nxt return times Passed All the test case

LeetCode : 3Sum Closest

 Question:https://leetcode.com/problems/3sum-closest/ Solution  class Solution :     def threeSumClosest ( self , nums : List[ int ], target : int ) -> int :         list_length = len (nums)         final_sum = 0         flag = 1         if list_length< 3 :             return 0         elif list_length == 3 :             return sum (nums)         else :             for len_nest1 in range ( 0 ,list_length- 2 ):                 for len_nest2 in range (len_nest1+ 1 ,list_length- 1 ):                     for len_nest3 in range (len_nest2+ 1 ,list_length):                         all_sum = nums[len_ne...