1945. Sum of Digits of String After Convert | math | strings | Leetcode Daily Challenge

preview_player
Показать описание
Problem Name:
1945. Sum of Digits of String After Convert

Problem Statement:
You are given a string s consisting of lowercase English letters, and an integer k.

First, convert s into an integer by replacing each letter with its position in the alphabet (i.e., replace 'a' with 1, 'b' with 2, ..., 'z' with 26). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operation k times in total.

Problem Link:

Solution Link:

Graph Playlist:

Java Plus DSA Placement Course Playlist:

Java Plus DSA Sheet:

Notes:

Telegram Link:

Ultimate Recursion Series Playlist:

Samsung Interview Experience:

Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung

Timestamp:
0:00 - Introduction

#ShashwatTiwari #coding​​ #problemsolving​
Рекомендации по теме
Комментарии
Автор

Yheee I hit the 100th like and I give respect to sir and their solution ...

OR mujhe sir se ye request hai ki app daily leetcode challenge ko upload kare jo ki hame mdad kregi
THNX

PerfectCapture
Автор

class Solution {
public:
int getLucky(string s, int k) {
int sum=0, temp, r, r1;
for(int i=0; i<s.length();i++)
{
temp=s[i]-96;
while(temp)
{
r=temp%10;
sum=sum+r;
temp=temp/10;
}
}

while(k>1)
{
int ans=0;
while(sum)
{
r1=sum%10;
ans=ans+r1;
sum=sum/10;
}
k--;
sum=ans;
}
return sum;
}
};

senankit
Автор

sitr how have you gotten the leetcode in dark mode?

ShylessThakur
Автор

public int getLucky(String s, int k){
int sum=0, n=s.length();
for(int i=0;i<n;i++){
int temp=s.charAt(i)-96;
while(temp>0){
int rem=temp%10;
sum+=rem;
temp/=10;
}
}
k--;
int num=sum;
while(k>0){
sum=0;
int temp=num;
while(temp>0){
int rem=temp%10;
sum+=rem;
temp/=10;
}
num=sum;
k--;
}
return sum;
}
🎉❤

dayashankarlakhotia
visit shbcf.ru