Day 1 of LeetCode Challenge

Cloud and DevOps Engineer with hands-on expertise in AWS, CI/CD pipelines, Docker, Kubernetes, and Monitoring tools. Adept at building and automating scalable, fault-tolerant cloud infrastructures, and consistently improving system performance, security, and reliability in dynamic environments.
Problem 1: Remove Trailing Zeros From a String

class Solution {
public String removeTrailingZeros(String num) {
while(num.length()>1){
if(num.charAt(num.length()-1)=='0')
num = num.substring(0, num.length()-1);
else
return num;
}
return num;
}
}
Problem 2: Self Dividing Numbers

class Solution {
public List<Integer> selfDividingNumbers(int left, int right) {
List<Integer> ans = new ArrayList<>();
for(int i=left; i<=right; i++){
String str = Integer.toString(i);
boolean bool = true;
String[] substrings = str.split("");
for(String j : substrings){
if(j.equals("0"))
bool = false;
else{
int num = Integer.parseInt(j);
if(i%num!=0)
bool = false;
}
}
if(bool==true)
ans.add(i);
}
return ans;
}
}
Problem 3: Pascal's Triangle II

public class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> res = new ArrayList<>();
res.add(1);
long prev = 1;
for (int k = 1; k <= rowIndex; k++) {
long next_val = prev * (rowIndex - k + 1) / k;
res.add((int) next_val);
prev = next_val;
}
return res;
}
}
Problem 4: Is Subsequence

class Solution {
public boolean isSubsequence(String s, String t) {
for(int i=0; i<s.length(); i++){
char ch1 = s.charAt(i);
boolean bool = false;
for(int j=0; j<t.length(); j++){
char ch2 = t.charAt(j);
if(ch1==ch2){
bool = true;
t = t.substring(j+1);
break;
}
}
if(!bool)
return false;
}
return true;
}
}
Problem 5: Construct the Longest New String

class Solution {
public int longestString(int x, int y, int z) {
if(x==y)
return ((x*2)+z)*2;
int num = (x<y)?x:y;
return (num+num+1+z)*2;
}
}




