/programmers_psets

solutions to programmers problem sets

Primary LanguageC++

programmers_psets ๐ŸŒŠ

solutions to programmers problem sets

๐Ÿ”“ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๊ณ ๋“์  Kit

  • 1. ํ•ด์‹œ (๋†’์Œ; 4 ๋ฌธ์ œ)
  • 2. ์Šคํƒ/ํ (๋ณดํ†ต 6 ๋ฌธ์ œ)
  • 3. ํž™ (๋ณดํ†ต; 4 ๋ฌธ์ œ)
  • 4. ์ •๋ ฌ (๋†’์Œ; 3 ๋ฌธ์ œ)
  • 5. ์™„์ „ํƒ์ƒ‰ (๋†’์Œ; 4 ๋ฌธ์ œ)
  • 6. ๊ทธ๋ฆฌ๋”” (๋‚ฎ์Œ; 7 ๋ฌธ์ œ)
  • 7. ๋™์ ๊ณ„ํš๋ฒ• (๋‚ฎ์Œ; 7 ๋ฌธ์ œ)
  • 8. ๊นŠ์ด/๋„ˆ๋น„ ์šฐ์„  ํƒ์ƒ‰ (๋†’์Œ; 4 ๋ฌธ์ œ)
  • 9. ์ด๋ถ„ํƒ์ƒ‰ (๋‚ฎ์Œ; 3๋ฌธ์ œ)
  • 10. ๊ทธ๋ž˜ํ”„ (๋‚ฎ์Œ; 4๋ฌธ์ œ)

๐Ÿซ ์นด์นด์˜ค ๋ธ”๋ผ์ธ๋“œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๊ธฐ์ถœ

  • ์นด์นด์˜ค ๋ธ”๋ผ์ธ๋“œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ 1์ฐจ 2019
  • ์นด์นด์˜ค ๋ธ”๋ผ์ธ๋“œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ 1์ฐจ 2018
  • ์นด์นด์˜ค ๋ธ”๋ผ์ธ๋“œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ 1์ฐจ 2017

๐Ÿ”ง Useful Mechanisms To Remember

list of useful mechanisms (functions) to remember

1. ํ•ด์‹œ

  1. use unordered_multiset to insert and erase duplicate keys (1-1. ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜)
    • use iterator to erase only one and not all duplicate keys
    • use unordered_map instead if need to count number of duplicates: (key, count)
      • bcuz duplicate keys are iterated separately in multiset
  2. sort and compare to check if prefix (1-1. ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜ & 1-2. ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก โญ)

  3. use counting principle to count all the possible combinations (1-3. ์œ„์žฅ ๐Ÿš€)
    • add not-chosen-case to each categories and multiply all categories
    • if there are certain instances not allowed, simpy calculate number of those and subtract from total counts
    • use backtracking instead, to actually create all the possible combination representations

2. ์Šคํƒ/ํ

3. ํž™

4. ์ •๋ ฌ

  1. use sort(v.begin() + i - 1, v.begin() + j) to sort range (i, j) (4-1. kth number)
    • make sure to copy array first and then use sort if need to preserve original array

5. ์™„์ „ํƒ์ƒ‰

8. ๊นŠ์ด/๋„ˆ๋น„ ์šฐ์„  ํƒ์ƒ‰