Coding | EXAMS | IBM ACCENTURE | VIRTUSA | IBM | AMAZON | TCS | EPAM | WILEY EDGE | TECH MAHINDRA | JPMORGAN | HCL | WIPRO
3.36K subscribers
1.13K photos
3 videos
17 files
373 links
Main channel https://t.me/Coding_000
Contact Admin 👉 @ILOVEU_143 for booking your exam slots
Web- https://coding000.github.io/Projects/
💯% clearance in any placement exams
OffCampus -https://t.me/Offcampus_000
Discussion- https://t.me/exams_discussion
Download Telegram
Coding | EXAMS | IBM ACCENTURE | VIRTUSA | IBM | AMAZON | TCS | EPAM | WILEY EDGE | TECH MAHINDRA | JPMORGAN | HCL | WIPRO
Photo
#include<bits/stdc++.h>
using namespace std;

bool check(char c1, char c2){
    if(c1==c2){
        return true;
    }
    if(c1=='a' && c2=='o'){
        return true;
    }
    if(c1=='o' && c2=='a'){
        return true;
    }
    if(c1=='t' && c2=='l'){
        return true;
    }
    if(c1=='l' && c2=='t'){
        return true;
    }
    return false;
}

bool helper(string &str, string &test, int n, int m, int K, bool mark, bool deleteOnce){
    if(m==0){
        return true;
    }
    if(n==0){
        return false;
    }
    bool res=false;
    if(check(str[n-1],test[m-1])==true){ 
        res=res | helper(str,test,n-1,m-1,K,true,deleteOnce);
    }
    if(K>0 && mark==true){  // mark represents that substring has started now, and now we can use K to ignore elements in this running substring
        res=res | helper(str,test,n-1,m,K-1,true,deleteOnce);
    }
    if(deleteOnce==false){  // delete once says, we can delete any character in ticket atleast once
        res=res | helper(str,test,n,m-1,K,mark,true);
    }
    if(mark==false){  // if mark is false, this means substring has not started yet, just move ahead in baseString
        res=res | helper(str,test,n-1,m,K,false,deleteOnce);
    }
    return res;
}

int main() {
    string s="aabacd";
    vector<string> str={"abcde","aoc","aabade"};
    int res=0;
    int K=2;
    for(auto e: str){
        if(helper(s,e,s.size(),e.size(),K,false,false)==true){
            res++;
        }
    }
    cout<<res;
    return 0;
}
👍1
def next_stepping_number(N):
    N = str(N)
    for i in range(len(N) - 1):
        if abs(int(N[i]) - int(N[i+1])) != 1:
            return int(N[:i+1] + str(int(N[i]) + 1 if int(N[i]) < int(N[i+1]) else int(N[i]) - 1) + '9'*(len(N)-i-1))
    return int(N) + 1

print(next_stepping_number(4))

python3
👍1
def getLargestString(s, k):
    frequency_array = [0] * 26

    for i in range(len(s)):

        frequency_array[ord(s[i]) -
                        ord('a')] += 1
    ans = ""
    i = 25
    while i >= 0:
        if (frequency_array[i] > k):
            temp = k
            st = chr( i + ord('a'))
            
            while (temp > 0):
                ans += st
                temp -= 1
          
            frequency_array[i] -= k
            j = i - 1
            
            while (frequency_array[j] <= 0 and
                   j >= 0):
                j -= 1
            if (frequency_array[j] > 0 and
                j >= 0):
                str1 = chr(j + ord( 'a'))
                ans += str1
                frequency_array[j] -= 1
            
            else:
                break
        elif (frequency_array[i] > 0):
            temp = frequency_array[i]
            frequency_array[i] -= temp
            st = chr(i + ord('a'))
            while (temp > 0):
                ans += st
                temp -= 1
        else:
            i -= 1
            
    return ans          

if name == "main":
  
    S = input()
    k = 3
    print (getLargestString(S, k))


Python
Bob code

Telegram:- @Coding_000
👍2