Power of Millets || Happy And Healthy Life

Image
Foundation Day Meeting : By   D. Anjaneyulu Reddy : Power of millets: When food is right no medicine is needed. When food is wrong no medicine works 1. Cosmetologist : due to unbalanced diet, regularly going to cosmetologist 2. Harmonal imbalance : hair loss 3. 1 gm of sugar / 1 litre of blood : It is good for health. 4. Staple food : It is eaten regularly , large part of person's diet. 5. Don't eat icecream as it increase the sugar content in blood. Embrace meaning : include , hug

Row with maximum ones || Leetcode Solution || Simple Approach || πŸ”₯πŸ”₯πŸ”₯πŸ’―πŸ’―πŸ’―βœ…βœ…βœ…||

             

                                2643. Row With Maximum Ones


Solution :-

Solving this problem using dictionary concept:

Approach Of solving the problem : 

  1. Create a empty dictionary d = {} , initialise count = 0 , lst = []
  2. Iterate over the mat list, now add dictionary for its index and count
  3. from the dictionary find the maximum value and store it in v_max variable
  4. Now iterate over the dictionary using .items() method
  5. Check condition if(value == v_max) append the key and value to the list and terminate the loop
  6. now, return the list

Complexity

  • Time complexity: 
O(n)

    Since we used for loops 

Code in Python:

class Solution:
    def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:
        count = 0 
        d = {}
        for i in mat:
            d[count] = i.count(1)
            count += 1 
        v_list = d.values()
        v_max = max(v_list)
        lst = []
        for key,value in d.items():
            if(value == v_max):
                lst.append(key)
                lst.append(value)
                break 
        return lst 

Comments

Popular posts from this blog

1050. Actors and Directors Who Cooperated At Least Three Times || Leetcode sql solution || Simple and Easy Approach || βœ…βœ…βœ…βœ…πŸ’―πŸ’―πŸ’―πŸ”₯πŸ”₯πŸ”₯πŸ”₯

Green newspaper in Japan

HOW TO PREPARE FOR JEE MAINS IN HOME EFFECTIVELY