└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # 📘 24 Days of JavaScript – Complete Question Bank 2 | 3 | A **structured JavaScript problem set** intended for: 4 | 5 | * Interview preparation 6 | * Data structures & algorithms practice 7 | * Strengthening JavaScript fundamentals 8 | 9 | --- 10 | 11 | ## 📌 General Instructions 12 | 13 | 1. Solve each problem using **JavaScript (ES6+)** 14 | 2. Do not use external libraries unless mentioned 15 | 3. Input and output formats must be followed exactly 16 | 4. Time and space efficiency should be considered where applicable 17 | 5. Write clean and readable code 18 | 19 | --- 20 | 21 | ## 🗓 Day 1 – Strings & Arrays (Fundamentals) 22 | 23 | ### 1. Remove duplicate characters from a string 24 | 25 | **Description:** 26 | Given a string, remove all duplicate characters while keeping the first occurrence order intact. 27 | 28 | **Input:** 29 | `"programming"` 30 | 31 | **Output:** 32 | `"progamin"` 33 | 34 | --- 35 | 36 | ### 2. Remove duplicate elements from an array and count occurrences 37 | 38 | **Description:** 39 | Given an array of numbers, return: 40 | 41 | * an array of unique elements 42 | * an object representing the frequency of each element 43 | 44 | **Input:** 45 | `[1, 2, 2, 3, 3, 3]` 46 | 47 | **Output:** 48 | 49 | ```js 50 | { 51 | unique: [1, 2, 3], 52 | count: { 1: 1, 2: 2, 3: 3 } 53 | } 54 | ``` 55 | 56 | --- 57 | 58 | ### 3. Remove duplicate elements using `filter` 59 | 60 | **Description:** 61 | Remove duplicate values from an array using the `filter` method. 62 | 63 | **Input:** 64 | `[1, 2, 2, 3, 4, 4]` 65 | 66 | **Output:** 67 | `[1, 2, 3, 4]` 68 | 69 | --- 70 | 71 | ### 4. Reverse a string without reversing individual words 72 | 73 | **Description:** 74 | Reverse the order of words in a sentence without changing the letters inside each word. 75 | 76 | **Input:** 77 | `"Hello World From JavaScript"` 78 | 79 | **Output:** 80 | `"JavaScript From World Hello"` 81 | 82 | --- 83 | 84 | ## 🗓 Day 2 – Basic Algorithms 85 | 86 | ### 5. Reverse a string with individual words reversed 87 | 88 | **Description:** 89 | Reverse the entire string including characters of each word. 90 | 91 | **Input:** 92 | `"Hello World"` 93 | 94 | **Output:** 95 | `"dlroW olleH"` 96 | 97 | --- 98 | 99 | ### 6. Reverse a string without using built-in reverse methods 100 | 101 | **Description:** 102 | Reverse a string without using `split()`, `reverse()`, or `join()`. 103 | 104 | **Input:** 105 | `"abcd"` 106 | 107 | **Output:** 108 | `"dcba"` 109 | 110 | --- 111 | 112 | ### 7. Find factorial of a number 113 | 114 | **Description:** 115 | Calculate the factorial of a given non-negative integer. 116 | 117 | **Input:** 118 | `5` 119 | 120 | **Output:** 121 | `120` 122 | 123 | --- 124 | 125 | ### 8. Check if two strings are anagrams 126 | 127 | **Description:** 128 | Determine whether two strings contain the same characters in the same frequency. 129 | 130 | **Input:** 131 | `"listen", "silent"` 132 | 133 | **Output:** 134 | `true` 135 | 136 | --- 137 | 138 | ### 9. Swap two numbers using a third variable 139 | 140 | **Input:** 141 | `a = 5, b = 10` 142 | 143 | **Output:** 144 | `a = 10, b = 5` 145 | 146 | --- 147 | 148 | ### 10. Swap two numbers without using a third variable 149 | 150 | **Input:** 151 | `a = 7, b = 3` 152 | 153 | **Output:** 154 | `a = 3, b = 7` 155 | 156 | --- 157 | 158 | ## 🗓 Day 3 – Palindrome & Word Problems 159 | 160 | ### 11. Check if a string or number is a palindrome using reverse 161 | 162 | **Input:** 163 | `"madam"` 164 | 165 | **Output:** 166 | `true` 167 | 168 | --- 169 | 170 | ### 12. Check if a string or number is a palindrome without reverse 171 | 172 | **Input:** 173 | `121` 174 | 175 | **Output:** 176 | `true` 177 | 178 | --- 179 | 180 | ### 13. Find the longest word in a sentence 181 | 182 | **Description:** 183 | Return the longest word from a sentence. 184 | 185 | **Input:** 186 | `"JavaScript is extremely powerful"` 187 | 188 | **Output:** 189 | `"extremely"` 190 | 191 | --- 192 | 193 | ## 🗓 Day 4 – String Analysis 194 | 195 | ### 14. Find the longest common prefix from an array of strings 196 | 197 | **Input:** 198 | `["flower", "flow", "flight"]` 199 | 200 | **Output:** 201 | `"fl"` 202 | 203 | --- 204 | 205 | ### 15. Count vowels and their occurrences 206 | 207 | **Input:** 208 | `"education"` 209 | 210 | **Output:** 211 | 212 | ```js 213 | { a: 1, e: 2, i: 1, o: 1, u: 1 } 214 | ``` 215 | 216 | --- 217 | 218 | ### 16. Count character frequency in a string 219 | 220 | **Input:** 221 | `"aabbbc"` 222 | 223 | **Output:** 224 | 225 | ```js 226 | { a: 2, b: 3, c: 1 } 227 | ``` 228 | 229 | --- 230 | 231 | ## 🗓 Day 5 – Array Pair Problems 232 | 233 | ### 17. Find the first pair whose sum is zero 234 | 235 | **Input:** 236 | `[-3, 1, 3, 4, -1]` 237 | 238 | **Output:** 239 | `[-3, 3]` 240 | 241 | --- 242 | 243 | ### 18. Find all pairs whose sum is zero 244 | 245 | **Input:** 246 | `[-2, 2, -1, 1, 3]` 247 | 248 | **Output:** 249 | 250 | ```js 251 | [[-2, 2], [-1, 1]] 252 | ``` 253 | 254 | --- 255 | 256 | ### 19. Find the largest pair from an unsorted array 257 | 258 | **Input:** 259 | `[10, 5, 20, 8]` 260 | 261 | **Output:** 262 | `[20, 10]` 263 | 264 | --- 265 | 266 | ## 🗓 Day 6 – Searching & Fibonacci 267 | 268 | ### 20. Find index of an element in an array 269 | 270 | **Input:** 271 | `[5, 8, 3, 9], 3` 272 | 273 | **Output:** 274 | `2` 275 | 276 | --- 277 | 278 | ### 21. Generate Fibonacci series up to N terms 279 | 280 | **Input:** 281 | `7` 282 | 283 | **Output:** 284 | `[0, 1, 1, 2, 3, 5, 8]` 285 | 286 | --- 287 | 288 | ## 🗓 Day 7 – Missing Numbers 289 | 290 | ### 22. Find the missing number in a sequence 291 | 292 | **Input:** 293 | `[1, 2, 4, 5]` 294 | 295 | **Output:** 296 | `3` 297 | 298 | --- 299 | 300 | ### 23. Find all missing numbers within a range 301 | 302 | **Input:** 303 | `[1, 3, 6]` 304 | 305 | **Output:** 306 | `[2, 4, 5]` 307 | 308 | --- 309 | 310 | ## 🗓 Day 8 – Sorting & Prime Numbers 311 | 312 | ### 24. Sort characters of a string alphabetically 313 | 314 | **Input:** 315 | `"dcba"` 316 | 317 | **Output:** 318 | `"abcd"` 319 | 320 | --- 321 | 322 | ### 25. Check if a number is prime 323 | 324 | **Input:** 325 | `13` 326 | 327 | **Output:** 328 | `true` 329 | 330 | --- 331 | 332 | ### 26. Print all numbers from 2 to 100 that are prime 333 | 334 | **Output:** 335 | `[2, 3, 5, 7, 11, ..., 97]` 336 | 337 | --- 338 | 339 | ## 🗓 Day 9 – Array & String Transformation 340 | 341 | ### 27. Find union of two arrays 342 | 343 | **Input:** 344 | `[1, 2, 3], [3, 4, 5]` 345 | 346 | **Output:** 347 | `[1, 2, 3, 4, 5]` 348 | 349 | --- 350 | 351 | ### 28. Find first duplicate element 352 | 353 | **Input:** 354 | `[1, 2, 3, 2, 4]` 355 | 356 | **Output:** 357 | `2` 358 | 359 | --- 360 | 361 | ### 29. FizzBuzz from 1 to 100 362 | 363 | **Output:** 364 | 365 | * Multiples of 3 → `"Fizz"` 366 | * Multiples of 5 → `"Buzz"` 367 | * Multiples of both → `"FizzBuzz"` 368 | 369 | --- 370 | 371 | ### 30. Capitalize first letter of each word 372 | 373 | **Input:** 374 | `"hello world"` 375 | 376 | **Output:** 377 | `"Hello World"` 378 | 379 | --- 380 | 381 | ## 🗓 Day 10 – 2D Arrays 382 | 383 | ### 31. Find the largest element from each row of a 2D array 384 | 385 | **Input:** 386 | 387 | ```js 388 | [ 389 | [1, 2, 3], 390 | [4, 9, 6], 391 | [7, 8, 5] 392 | ] 393 | ``` 394 | 395 | **Output:** 396 | `[3, 9, 8]` 397 | 398 | --- 399 | 400 | ## 🗓 Day 24 – Advanced Array Problem 401 | 402 | ### 32. Find all unique triplets whose sum equals a given value 403 | 404 | **Description:** 405 | Return all unique triplets where the sum of three numbers equals the target value. 406 | 407 | **Input:** 408 | `[-1, 0, 1, 2, -1, -4], 0` 409 | 410 | **Output:** 411 | 412 | ```js 413 | [ 414 | [-1, -1, 2], 415 | [-1, 0, 1] 416 | ] 417 | ``` 418 | 419 | --- 420 | 421 | ### 33. Convert an array into an object 422 | 423 | **Input:** 424 | `["A", "B", "C"]` 425 | 426 | **Output:** 427 | 428 | ```js 429 | { 0: "A", 1: "B", 2: "C" } 430 | ``` 431 | --------------------------------------------------------------------------------