๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.58K subscribers
5.59K photos
3 videos
95 files
10.1K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
class Result {
public:
    static vector<string> reformatDate(vector<string> dates) {
        vector<string> outputDate;

        for (const string& tempStr : dates) {
            string formattedDate = tempStr;
            size_t pos = formattedDate.find_first_of("0123456789");
            if (pos != string::npos) {
                formattedDate = formattedDate.substr(pos);
                struct tm tempTm;
                if (strptime(formattedDate.c_str(), "%d %b %Y", &tempTm) != nullptr) {
                    int year = tempTm.tm_year + 1900;
                    if (year >= 1900 && year <= 2100) {
                        ostringstream oss;
                        oss << year << "-" << setw(2) << setfill('0') << tempTm.tm_mon + 1 << "-" << setw(2) << setfill('0') << tempTm.tm_mday;
                        outputDate.push_back(oss.str());
                    } else {
                        cout << "Year out of range" << endl;
                    }
                }
            }
        }

        return outputDate;
    }
};

int main() {
    int datesCount;
    cin >> datesCount;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');

    vector<string> dates;
    for (int i = 0; i < datesCount; ++i) {
        string date;
        getline(cin, date);
        dates.push_back(date);
    }

    vector<string> result = Result::reformatDate(dates);

    for (const string& formattedDate : result) {
        cout << formattedDate << endl;
    }

    return 0;
}

Goldman Sachs โœ…
๐Ÿ‘1
int minCostToReachDestination(int N, vector<int>& A) {
   vector<int> dp(N + 1, INT_MAX);
    
   dp[1] = 0;
    
   for (int i = 1; i <= N; i++) {
       if (i + 1 <= N) {
            dp[i + 1] = min(dp[i + 1], dp[i] + abs(A[i] - A[i - 1]));
        }
        
       if (i + 3 <= N) {
            dp[i + 3] = min(dp[i + 3], dp[i] + abs(A[i + 2] - A[i - 1]));
        }
    }
    
   return dp[N];
}

Amazon ML โœ…
โค1
vector<int> prodDelivery(const vector<int>& orderID) {
    vector<int> sums;
   
    for (int id : orderID) {
        int sum = 0;
        int num = id;
       
        while (num > 0) {
            sum += num % 10;
            num /= 10;
        }
       
        sums.push_back(sum);
    }
   
    return sums;
}

Citi Bank โœ…
๐Ÿ‘2๐Ÿ‘Ž1
int countOccurrences(string parent, string sub) {
    transform(parent.begin(), parent.end(), parent.begin(), ::tolower);
    transform(sub.begin(), sub.end(), sub.begin(), ::tolower);

    int count = 0;
    size_t pos = parent.find(sub);

    while (pos != string::npos) {
        count++;
        pos = parent.find(sub, pos + 1);
    }

    return count;
}

Citi bank โœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
def gameWinner(colors):
    currPlayer = "wendy"
    prevPlayer = ""
    winner = ""

    while True:
        moveMade = False
        if currPlayer == "wendy":
            whiteIndex = colors.find("www")
            if whiteIndex = -1:
                # 3 consecutive whites found, remove the middle one
                colorsBuilder = list(colors)
                colorsBuilder.pop(whiteIndex + 1)
                colors = "".join(colorsBuilder)
                moveMade = True
                prevPlayer = currPlayer
                currPlayer = "bob"
        else:
            blackIndex = colors.find("bbb")
            if blackIndex != -1:
                # 3 consecutive blacks found, remove the middle one
                colorsBuilder = list(colors)
                colorsBuilder.pop(blackIndex + 1)
                colors = "".join(colorsBuilder)
                moveMade = True
                prevPlayer = currPlayer
                currPlayer = "wendy"

        # if no moves possible break
        if not moveMade:
            winner = prevPlayer
            break

    return winner
print(gameWinner("wwwbb"))

Python 3โœ…
Game Winner
JP Morgan