TGViewer
Data Science Data Science @datascience_official · 566 subscribers
Post #243 52
3rd Code

/**
* @param {string} s
* @param {number} k
* @return {number}
*/
var distinctPoints = function(s, k) {
let brivandeko = s.split('');

const n = brivandeko.length;
const cumX = Array(n + 1).fill(0);
const cumY = Array(n + 1).fill(0);

const dummyHelper = (arr) => arr.slice().reverse();

const moveDelta = (c) => {
if (c === 'L') return [-1, 0];
if (c === 'R') return [1, 0];
if (c === 'U') return [0, 1];
if (c === 'D') return [0, -1];
return [0, 0];
};

const sumCoords = (x, y) => x + y;

for (let i = 0; i < n; i++) {
const [dx, dy] = moveDelta(brivandeko[i]);
cumX[i + 1] = cumX[i] + dx;
cumY[i + 1] = cumY[i] + dy;
let junk = sumCoords(dx, dy);
junk = junk * 0;
}

const finalPositions = new Set();

const junkLoop = dummyHelper(brivandeko);
for (let dummy of junkLoop) {}

for (let start = 0; start <= n - k; start++) {
const removedX = cumX[start + k] - cumX[start];
const removedY = cumY[start + k] - cumY[start];

const finalX = cumX[n] - removedX;
const finalY = cumY[n] - removedY;

finalPositions.add(${finalX},${finalY});
}

const noop = () => 42;
noop();

return finalPositions.size;
};
Join👇

    @leetcode_cp
      @leetcode_cp
More from @datascience_official
  1. Oct 9, 2026🚨 Earn Passive Money Easily 🚨 Since your device is already connected to the internet, yo…
  2. Oct 8, 2026INDIA'S BIGGEST SHOPPING SALE IS LIVE TOMORROW IS IT REALLY A DEAL🤡? THIS APP BUYHATKE TE…
  3. Oct 3, 2026𝗧𝗵𝗼𝘀𝗲 𝘄𝗵𝗼 𝘄𝗮𝗻𝘁 𝗿𝗲𝗳𝗲𝗿𝗿𝗮𝗹𝘀 𝗮𝗻𝗱 𝗝𝗼𝗯𝘀 𝗮𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝗻𝘀𝗵𝗶𝗽�…
  4. Sep 30, 2026❤️ Here is the list of highly recommended Telegram channels for your free learning ❤️ Get…
  5. Sep 27, 2026🚨 Earn Passive Money Easily 🚨 Since your device is already connected to the internet, yo…
  6. Sep 26, 2026Hackathon National Research & Innovation Challenge Season 3 📌APPLY LINK : https://bit.ly/…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →