Back to Browse

Python : Number of Changing Keys

84 views
Feb 16, 2024
11:19

Video 88: In this video, we explore the number of times we change keys while typing the string. You are given a string typed by a user. Changing a key is defined as using a key different from the last used key. For example, s = "ab" has a change of a key while s = "bBBb" does not have any. Modifiers like shift or caps lock won't be counted in changing the key that is if a user typed the letter 'a' and then the letter 'A' then it will not be considered as a changing of key. Return the number of times the user had to change the key while typing the string. Since we are not considering the Shift or Caps keys, the string is considered case-insensitive. Therefore, we need to scan through the string and check if the current character is the same as the previous one. If it's not, there is a change in the key. Since it's a zero-indexed string, we ensure that we compare the index position starting from 1 and begin the counter from there. In this video, we discuss two different approaches. *** Approach 1: Assigning the Previous Character to a Variable *** In this approach, we assign the previous character to a variable and compare it with the current character. If they do not match, we increment the counter by one. *** Approach 2: Comparing the Current and Previous Characters Each Time *** In this approach, we scan through the string and compare the current character with the previous one. We use the "enumerate" function to obtain the index and value of the current element. For an in-depth understanding of these Python code, please refer to the comprehensive explanatory video. code: https://github.com/jeganpillai/python_reference/blob/main/p0039_number_of_changing_keys.py Follow me on, Website : https://growwithdata.co/ YouTube : https://www.youtube.com/@growwithdata TikTok : https://www.tiktok.com/@growwithdata LinkedIn : https://www.linkedin.com/company/growwithdata/ Facebook : https://www.facebook.com/growwithdata.co/ twitter : https://twitter.com/growwithdata_co WhatsApp : https://whatsapp.com/channel/0029VaF8pkb77qVNfbp5pA0S Instagram : https://www.instagram.com/growwithdata.co/ #recursive #countingalgorithm #list #looping #listmanipulation #uniquesubstring #longestsubstring #slicing #lineartimecomplexity #python #pythonquestions #pythontest #pythonprogramming #pythontutorial #python3 #pythonforbeginners #interviewquestions #interview #dataengineers #deinterview #pythoninterview #interviewquestions #leetcode #placementpreparation #meta #google #facebook #apple #netflix #amazon #google #faang #maanga #dataengineers #alphanumeric #nonalphanumeric #growwithdata #set #split #remove #pythonfunctions

Download

0 formats

No download links available.

Python : Number of Changing Keys | NatokHD