tsvk's blog

By tsvk, history, 4 days ago, In English

You are given a list of coordinates that represent the bottom left and top right coordinates of the rectangle. You have to find a line parallel to the y-axis which will divide all the rectangles into 2 equal halves.

Overlapping is allowed....

I gave an approach but interviewer didn't seem convinced. Can you guys share any approaches?

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it

By tsvk, history, 3 months ago, In English

Recently I had been trying to solve a question :

I have come up with the following approach :

#include "bits/stdc++.h"
using namespace std;
const int MOD = 1000000007;
vector<int> getValidRep(const vector<int>& arr, int i, int m) {
    vector<int> vec;
    if (i == 0) {
        for (int i = 1; i <= m; i++) {
            if (i != arr[i + 1]) 
                vec.push_back(i);
        }
    } 
    else if (i == arr.size() - 1) {
        for (int i = 1; i <= m; i++) {
            if (i != arr[i - 1]) 
                vec.push_back(i);
        }
    } 
    else {
        for (int i = 1; i <= m; i++) {
            if (i != arr[i - 1] && i != arr[i + 1])
                vec.push_back(i);
        }
    }
    return vec;
}

int f(const vector<int>& arr, int n, int m) {
    int totWays = 1;
    for (int i = 0; i < n; i++) {
        if (arr[i] == -1) {
            vector<int> vec = getValidRep(arr, i, m);
            totWays = (static_cast<long long>(totWays) * vec.size()) % MOD;
        }
    }
    return totWays;
}

int main() {
    int n = 5;
    vector<int> v(n);
    for(auto &it : v) cin>>it;
    int m = 5;
    cout << f(v, n, m) << endl; 
    return 0;
}

The thing is that , I cannot submit to test for the test cases as it was part of an OA and I can't find it on any online judge and I am not able to think of anythinf better. All kinds of inputs will be appreciated... Thanks

Full text and comments »

  • Vote: I like it
  • -11
  • Vote: I do not like it

By tsvk, history, 16 months ago, In English

Recently , Google discontinued its coding competitions and this lead to a discussion in the community that is CP dead. Well here , I have summed up my opinion. Q. Is CP dead ? A. No, CP is not dead even after Google has discontinued its Coding Competitions. While Google's Coding Competitions provided a platform for programmers to compete and showcase their skills, there are still many other online platforms and competitions available for competitive programming enthusiasts.

Some popular online platforms for CP include Codeforces, Topcoder, Atcoder, LeetCode, HackerRank, and CodeChef, among others. These platforms regularly host coding contests and provide a forum for participants to hone their skills and compete with other programmers from around the world.

Additionally, CP has gained popularity in recent years as an essential skill for technical interviews in the software industry. Therefore, the demand for competitive programming skills is unlikely to diminish anytime soon. So, while Google's Coding Competitions may have ended, CP remains a thriving community with numerous opportunities for programmers to showcase their skills and learn from others.

CP today , has become more of a mind sport which furnishes you with great problem solving skills. If you have been a CP loving person , you know that the Green "Accepted" output is the second most pleasurable thing in the universe . So , if you are unable to find the reason to do CP , do it for the Accepted Mark. ( Yeah , I know that this part is a little cringe but OK ☺ )

Full text and comments »

  • Vote: I like it
  • -29
  • Vote: I do not like it