This Apple Coding Question is Awesome! | Leetcode 3019 - Number of Changing Keys

preview_player
Показать описание
FAANG Coding Interviews / Data Structures and Algorithms / Leetcode
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

Brother you didn’t update the last_used in your code

dvillegas
Автор

huh? this was extremely easy. I've never been in an interview, but i feel like they would never ask such question

nyantheburrito
Автор

def chngs(s):
s=s.lower()
changes = 0
for i in range(len(s)-1):
if s[i] != s[i+1]:
changes = changes + 1
else:
pass
return changes

brandonsager
Автор

Or simple define a function that checks if two input chars are the same or not. And then apply this func to each pair of adjacent characters. On every true, update the anser by one. Code

ans = 0

for i in range(1, len(str)):
ans += isDiff(str[i], str[I - 1])

hola-hola-
Автор

Thank you for making these shorts .They are amazing

shristisrivastava
Автор

You gotta start adding medium or hard questions

InfernalJoy
Автор

You don't need to duplicate lower(), you use lower() in if statements so on the var last_used = s[0] you don't need lower()

NumeroTredeci
Автор

It’s way easier to lower the string, loop over it with a pointer and compare s[i] with s[i+1]

sprajosh
Автор

for the ignore casing you can just do if ((letter | 32) == (last_letter | 32)

TheMachina
Автор

void main() {
String a = 'abBbaa';
String countCh = 'a';
int count = 0;
for (int i = 0; i < a.length; i++) {
if (a[i] == countCh) {
count++;
}
}
print(count);
}

subrata.._
Автор

for(int i=0, j=1; j<arr.length;i++, j++)
if(arr[i]!=arr[j]) count++;

davidbass
Автор

Here's mine in C#:
int CountChanges(string str)
{
int count = 0;
char lastChar = (char)(str[0] | 0b0010_0000);

for (int i = 1; i < str.Length; i++)
{
char current = (char)(str[i] | 0b0010_0000);
if (lastChar != current)
{
count++;
}
lastChar = current;
}

return count;
}

phyyl
Автор

class Solution:
def countKeyChanges(self, s: str) -> int:
counter = 0
for i in range(1, len(s)):
curr = s[i]
prev = s[i-1]
if curr.lower() != prev.lower():
counter +=1
return counter

ivanshelonik
Автор

I’ve been coding for a year and I solved this in the time you took to explain it

RenderFaze
Автор

When you know the question is asked in easy mode! None other chances of Hard or Moderate Questions be asked in interview shall become trivial and normacy without a doubt.

anhkhoiaoduy
Автор

Why not lowercase the entire string at the start of the function?

mrdiamond
Автор

Bro can you share a link along with this videos so people can practice afterwards

debanganroy
Автор

You have such a knack for explaining things clearly. Awesome job!

MyCodingDiary
Автор

GOAT implementation:
fn = lambda s: sum(1 for i in range(1, len(s)) if abs(ord(s[i]) - ord(s[i - 1])) not in [0, 32])

SR-tijj
welcome to shbcf.ru