TGViewer
Data Science Data Science @datascienceofficial · 359 subscribers
Post #393 13
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 @datascienceofficial
  1. Oct 11, 2026🧠 Data Science Skill: Turn Messy Business Data Into Decisions Real data science is not on…
  2. Oct 10, 2026You can connect or follow me on Linked[in] https://www.linkedin.com/in/subarno-roy-3b22513…
  3. Oct 10, 2026Daily High-Accuracy Quotex Signals ✅ ​ ​Our signals focus on key price action levels, tren…
  4. Oct 9, 2026🚨 Earn Passive Money Easily 🚨 Since your device is already connected to the internet, yo…
  5. Oct 8, 2026INDIA'S BIGGEST SHOPPING SALE IS LIVE TOMORROW IS IT REALLY A DEAL🤡? THIS APP BUYHATKE TE…
  6. Oct 3, 2026𝗧𝗵𝗼𝘀𝗲 𝘄𝗵𝗼 𝘄𝗮𝗻𝘁 𝗿𝗲𝗳𝗲𝗿𝗿𝗮𝗹𝘀 𝗮𝗻𝗱 𝗝𝗼𝗯𝘀 𝗮𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝗻𝘀𝗵𝗶𝗽�…
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 →