allcoding1
27.7K subscribers
2.2K photos
3 videos
74 files
850 links
Download Telegram
#include <bits/stdc++.h>
using namespace std;

int jumps(int flagHeight, int bigJump) {
    return flagHeight / bigJump+flagheight% bigJump;

}. 

Swiggy

Jump to The Flag


Telegram:- @allcoding1
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int findLIS(vector<int>& s) {
    vector<int> tails;

    for (int x : s) {
        auto it = lower_bound(tails.begin(), tails.end(), x);
        if (it == tails.end()) {
            tails.push_back(x);
        } else {
            *it = x;
        }
    }

    return tails.size();
}  

Swiggy
LIS

Telegram:- @allcoding1
int solve(int k, vector<int>& s) {
    sort(s.rbegin(), s.rend());
    int c = 0;
    for (int i = 0; i < s.size(); i++) {
        if (i < k && s[i] > 0) {
            c++;
        } else if (s[i] == s[i - 1] && s[i] > 0) {
            c++;
        } else {
            break;
        }
    }
    return c;
}

Competitive Gaming

Accenture exam

Telegram:- @allcoding1
👍1
import re

a = int(input().strip())
b = set()
c = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'

for _ in range(a):
    line = input().strip()
    b.update(re.findall(c, line))

print(';'.join(sorted(b)))

Accenture exam

Telegram:- @allcoding1
👍1
Accenture exam

Telegram:- @allcoding1
Accenture exam

Telegram:- @allcoding1
Accenture exam

Telegram:- @allcoding1
Accenture exam

Telegram:- @allcoding1
allcoding1
Photo
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int numDecodings(string msg) {
    int MOD = 1000000007;
    int n = msg.size();
   
    vector<long long> dp(n + 1, 0);
    dp[0] = 1;
   
    if (msg[0] == '0')
        dp[1] = 0;
    else if (msg[0] == '*')
        dp[1] = 9;
    else
        dp[1] = 1;
   
    for (int i = 2; i <= n; ++i) {
        if (msg[i - 1] == '0') {
           
            if (msg[i - 2] == '1' || msg[i - 2] == '2')
                dp[i] += dp[i - 2];
            else if (msg[i - 2] == '*')
                dp[i] += 2 * dp[i - 2];
        } else if (msg[i - 1] >= '1' && msg[i - 1] <= '9') {
     
            dp[i] += dp[i - 1];
           
            if (msg[i - 2] == '1' || (msg[i - 2] == '2' && msg[i - 1] <= '6'))
                dp[i] += dp[i - 2];
            else if (msg[i - 2] == '*') {
               
                if (msg[i - 1] <= '6')
                    dp[i] += 2 * dp[i - 2];
                else
                    dp[i] += dp[i - 2];
            }
        } else if (msg[i - 1] == '*') {
            dp[i] += 9 * dp[i - 1];
           
            if (msg[i - 2] == '1')
                dp[i] += 9 * dp[i - 2];
            else if (msg[i - 2] == '2')
                dp[i] += 6 * dp[i - 2];
            else if (msg[i - 2] == '*')
                dp[i] += 15 * dp[i - 2];
        }
       
        dp[i] %= MOD;
    }
   
    return dp[n];
}

Number of ways decode


Accenture exam

Telegram:- @allcoding1
👍1
heights = [int(i) for i in input().split()]
freq_dict = {}
for h in heights:
if h in freq_dict:
  freq_dict[h] += 1
else:
  freq_dict[h] = 1
for h in sorted(freq_dict):
print(h, freq_dict[h])

Accenture exam

Telegram:- @allcoding1
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

std::string stemmer(const std::string& text) {
    std::stringstream ss(text);
    std::string word;
    std::vector<std::string> stemmed_words;

    while (ss >> word) {
        if (word.size() > 2 && (word.substr(word.size() - 2) == "ed" word.substr(word.size() - 2) == "ly" word.substr(word.size() - 3) == "ing")) {
            word = word.substr(0, word.size() - 2);
        }
        if (word.size() > 8) {
            word = word.substr(0, 8);
        }
        stemmed_words.push_back(word);
    }

    std::string result;
    for (const std::string& stemmed_word : stemmed_words) {
        result += stemmed_word + " ";
    }


    result.pop_back();
    return result;
}

int main() {
    std::string text = "an extremely dangerous dog is barking";
    std::cout << stemmer(text) << std::endl;  // Output: "an extreme dangerou dog is bark"

    return 0;
}

Suffix stripping stemmer

Telegram:- @allcoding1
👍1
class Message(object):
    def init(self, message: str, sender: int, receiver: int) -> None:
        self.message = message
        self.sender = sender
        self.receiver = receiver

    def str(self) -> str:
        return self.message

    def eq(self, other: object) -> bool:
        if not isinstance(other, Message):
            return False
        return self.message == other.message

Message Objects

Telegram:- @allcoding1
🎯Infosys Recruitment Drive 2024 | Hiring For Process Executive , Salary Up to ₹3.5 LPA

Degree:- Any Bachelor's
Batch:- 2021, 2022, 2023 & 2024

Apply now:- www.allcoding1.com
👍2
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

long getkRepValue(string user_history, long k) {
    long n = user_history.size();
    unordered_map<char, long> count;
    long left = 0, right = 0, ans = 0;

    while (right < n) {
        count[user_history[right]]++;
        while (count[user_history[right]] >= k && left <= right) {
            ans += n - right;
            count[user_history[left]]--;
            left++;
        }
        right++;
    }

    return ans;


Machine learning
Amazon
👍2
int solve(vector<int> tc) {
    int n = tc.size();
    vector<int> p(n), s(n);

    p[0] = tc[0];
    for (int i = 1; i < n; ++i) {
        p[i] = p[i - 1] + tc[i];
    }

    s[n - 1] = tc[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        s[i] = s[i + 1] + tc[i];
    }

    int m = max(p[0], s[0]);
    for (int i = 1; i < n; ++i) {
        m = max(m, max(p[i], s[i]));
    }

    return m;
}

Amazon
👍3