๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.57K subscribers
5.58K photos
3 videos
95 files
9.98K 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
function findShortestPath(N, bricks) {
  let visited = new Set();
  let queue = [[0, 0]];

  while (queue.length > 0) {
    let [position, moves] = queue.shift();

    if (position === N - 1) {
      return moves;
    }

    visited.add(position);
    if (position + 1 < N && bricks[position] === bricks[position + 1] && !visited.has(position + 1)) {
      queue.push([position + 1, moves + 1]);
    }

    if (position - 1 >= 0 && bricks[position] === bricks[position - 1] && !visited.has(position - 1)) {
      queue.push([position - 1, moves + 1]);
    }

    for (let i = 0; i < N; i++) {
      if (bricks[i] === bricks[position] && !visited.has(i)) {
        queue.push([i, moves + 1]);
      }
    }
  }
  return -1;
}

Dorothy has been caught up
process.stdin.on('data', data => {
  inputArr.push(data.toString().trim());
  if (++count === 3) {
    console.log(divideMutantsIntoTeams(inputArr));
    process.exit(0);
  }
});

function divideMutantsIntoTeams(inputArr){
  let N = parseInt(inputArr[0], 10);
  let K = parseInt(inputArr[1], 10);
  let mutants = inputArr[2].split(' ').map(Number);


  if (N < K || new Set(mutants).size === 1 || N % K !== 0) {
    return -1;
  }


  mutants.sort((a, b) => a - b);
  let minNonCompatibilityScore = Infinity;

  for (let i = 0; i <= N - K; i++) {
    let diff = mutants[i + K - 1] - mutants[i];
    if (diff < minNonCompatibilityScore) {
      minNonCompatibilityScore = diff;
    }
  }

  return minNonCompatibilityScore;
}

Xaviers Fight with magento
var stdin process.openStdin();
stdin.addListener("data", function(d) {

// note: d is an object, and when converted to a string it will
// end with a linefeed. so we (rather crudely) account for that
// with toString() and then trim()
console.log(d.toString().trim());

});


Driver Code โœ…
let fs = require("fs");

function longestSubstringTwoDistinct(s) {
    let maxLen = 0;
    let startIndex = 0;
    let charIndexMap = new Map();

    for (let i = 0; i < s.length; i++) {
        charIndexMap.set(s[i], i);
        if (charIndexMap.size > 2) {
            let minIndex = Math.min(...charIndexMap.values());
            charIndexMap.delete(s[minIndex]);
            startIndex = minIndex + 1;
        }
        maxLen = Math.max(maxLen, i - startIndex + 1);
    }

    return maxLen;
}

function Main(arg) {
   
    let inputString = String(arg);
  return longestSubstringTwoDistinct(inputString);
}
#include<bits/stdc++.h>
using namespace std;

vector<int> getExecTime(int n, vector<string> logs) {
    vector<int> res(n, 0);
    stack<int> st;
    int prev = 0;

    for(string log : logs) {
        stringstream ss(log);
        string buf;
        getline(ss, buf, ':');
        int id = stoi(buf);
        getline(ss, buf, ':');
        string type = buf;
        getline(ss, buf, ':');
        int time = stoi(buf);

        if(!st.empty()) {
            res[st.top()] += time - prev;
        }

        prev = time;

        if(type == "start") {
            st.push(id);
        } else {
            res[st.top()]++;
            st.pop();
            prev++;
        }
    }

    return res;
}

IBMโœ