Блог пользователя prakharmishra

Автор prakharmishra, история, 8 месяцев назад, По-английски

Hello Everyone,

  1. I found this C++ STL (standard template library) sheet online. Useful for someone starting out. Contains mostly everything about the basic data structures and how to implement them.
    Attaching link to pdf, Link

  2. Also attaching a small document I made, contains frequently used functions and tricks like finding MEX of array, nCr(combination), GCD, LCM, Seive, binary exponentiation for finding power etc.
    Attaching link to document, Link

Preview,


PS: Please suggest if you have more such functions or notice any errors and I'll fix them right away.
UPD: Added some questions in the document to practice.
UPD2: A list of most commonly asked DSA algorithms in interviews — Link

Полный текст и комментарии »

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится

Автор prakharmishra, история, 12 месяцев назад, По-английски
  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

Автор prakharmishra, история, 14 месяцев назад, По-английски

Hello everyone, I was trying to solve this problem, 1765N - Number Reduction. I wrote a code and its logic is same as the editorial but rather than finding from digit '0' to '9' which is occurs first in the next 'k+1' elements in the number from left to right, I just searched the minimum among the 'k+1'.

My code works on almost all testcases except when the input is increasing, like n=1337 and k=2. Answer should be 13 but mine gives garbage value.

Here is my code,

My Code

I saw authors code solutions using stack to keep the smallest elements. Can someone provide me some corrections in my code, or will i need to implement stack solution?

Edit
Solved the edge case by removing elements from end when k!=0 after traversing through the number. But got TLE as the increasing sequence will always check for minimum from the next 'k+1' elements of each index, resulting in worst case O(n^2) solution. Maintaining stack is the most optimal way to keep the smallest numbers.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится