Maximum Odd Binary Number | 2 Approaches | Leetcode 2864
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 23rd Video of our Playlist "Leetcode Easy : Popular Interview Problems".
In this video we will try to solve a good practice problem : Maximum Odd Binary Number | Leetcode 2864
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 : Maximum Odd Binary Number | 2 Approaches | Leetcode 2864
Company Tags : will update soon
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Greedy/Leetcode%20Easy/Maximum%20Odd%20Binary%20Number.cpp
Leetcode Link : https://leetcode.com/problems/maximum-odd-binary-number
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Approach Summary :
Approach-1 (Greedy Assignment of 1s):
In this approach, the algorithm greedily assigns '1' bits from the input binary string to the result string. It iterates through each character of the input string, and whenever it encounters a '1', it assigns it to the result string. If the last position of the result string is already '1', it assigns '1' to the next available position. The time complexity is O(n), where n is the length of the input string, and the space complexity is also O(n) for the result string.
Approach-2 (Count 1s and Assign):
This approach first counts the number of '1' bits in the input binary string. It then iteratively assigns '1' bits to the result string based on the count. The algorithm continues assigning '1' bits until only one '1' bit remains in the count, and the last position of the result string is set to '1'. The time complexity is O(n), where n is the length of the input string, and the space complexity is O(n) for the result string.
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
✨ Timelines✨
00:00 - Introduction
02:27 - What you should know ?
05:48 - Approach-1
08:33 - Approach-2
10:36 - Time & Space
11:21 - Coding it up
#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 #2024 #newyear