Загрузка...

Prime List Problem solved in JS | GeeksforGeeks | POTD | Streak 154 | Sat, 03 May 2025 | NCS

You are given the head of a linked list. You have to replace all the values of the nodes with the nearest prime number. If more than one prime number exists at an equal distance, choose the smallest one. Return the head of the modified linked list.

Examples :

Input: head = 2 → 6 → 10
Output: 2 → 5 → 11

Explanation: The nearest prime of 2 is 2 itself. The nearest primes of 6 are 5 and 7, since 5 is smaller so, 5 will be chosen. The nearest prime of 10 is 11.
Input: head = 1 → 15 → 20
Output: 2 → 13 → 19

Explanation: The nearest prime of 1 is 2. The nearest primes of 15 are 13 and 17, since 13 is smaller so, 13 will be chosen. The nearest prime of 20 is 19.

---
introduction:
name: "Jagadeesh Kumar S"
contact: "+91 73972 85837 | 33x23@pm.me"
description: "A problem-solving enthusiast passionate about coding challenges."

technical_achievements:
- "Solved 100+ daily coding challenges on GeeksforGeeks"
- "Ranked in the top 130 on SRM Institute of Science and Technology's GeeksforGeeks leaderboard"
- "Maintained a 100+ day streak for Problem of the Day"

github:
contributions: "Solutions available at https://github.com/JKS-sys/Solution-To-Problem-Of-The-Day-at-geeksforgeeks.org"
---

Видео Prime List Problem solved in JS | GeeksforGeeks | POTD | Streak 154 | Sat, 03 May 2025 | NCS канала NewsCraft Studio (by JKS)
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять