Score After Flipping Matrix | Modifying | Without Modifying Input | Leetcode 861 | codestorywithMIK

Опубликовано: 03 Ноябрь 2024
на канале: codestorywithMIK
6,456
286

Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 14th Video of our Playlist "Bit-Manipulation : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a very good bit manipulation problem based on 2D array : Score After Flipping Matrix | Modifying Input | Without Modifying Input | Leetcode 861 | codestorywithMIK

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Score After Flipping Matrix | Modifying Input | Without Modifying Input | Leetcode 861 | codestorywithMIK
Company Tags : AMAZON
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/score-a...


My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram :   / codestorywithmik  
Facebook :   / 100090524295846  
Twitter :   / cswithmik  
Subscribe to my channel :    / @codestorywithmik  

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Summary :
Sure, here's a summary of the two approaches:

Approach-1 (Modifying the input)
*Time Complexity (T.C):* \( O(m \times n) \)
*Space Complexity (S.C):* \( O(1) \)
*Summary:*
Iterate over each row and check the value of the first element (column) in the row.
If it's 0, flip the entire row.
Then iterate over each column starting from the second one.
Count the number of 0s and 1s in each column and flip the column if there are more 0s than 1s.
Calculate the score by multiplying each cell's value with its corresponding weight (2 raised to the power of its position from the right).
Return the final score.

Approach-2 (Without Modifying the input)
*Time Complexity (T.C):* \( O(m \times n) \)
*Space Complexity (S.C):* \( O(1) \)
*Summary:*
Calculate the initial score by considering only the first column (MSB) weight, which is \( 2^{n-1} \) multiplied by the number of rows.
Iterate over each column (excluding the first one) and count the number of 1s in each column that have the same value as the first element of its corresponding row.
Calculate the additional contribution to the score by considering the weight of each column (excluding the MSB) multiplied by the maximum count of 1s or 0s in that column.
Add this additional contribution to the initial score.
Return the final score.

Both approaches achieve the same result of calculating the maximum possible score of the given binary matrix, with the primary difference being in how they handle the matrix manipulation (modifying vs. not modifying the input matrix) and how they calculate the score.

✨ Timelines✨
00:00 - Introduction

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024