├── LICENSE ├── BecomeAContributors.md ├── README.md ├── PS-Sprint-3 └── README.md ├── PS-Sprint-2 └── README.md └── PS-Sprint-1 └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Preparation Street 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /BecomeAContributors.md: -------------------------------------------------------------------------------- 1 | # Contribution Guide 2 | 3 | Welcome to our journey in the world of Data Structures and Algorithms (DSA)! If you're ready to start your DSA journey, take the first step with us by solving the problems in this repository. Follow these steps to contribute and be part of our community: 4 | 5 | ## How to Contribute 6 | 7 | 1. **Solve the Problems:** 8 | - Browse through the problem set provided in this repository. 9 | - Solve all the problems and document your solutions. 10 | 11 | 2. **Create a Pull Request (PR):** 12 | - Once you have solved a problem, name your PR with a meaningful title. 13 | - Merge your solution into the repository. 14 | 15 | 3. **Review and Merge:** 16 | - Your solutions will be reviewed and merged into the repository. 17 | - Each merged PR will help us build a comprehensive resource for DSA. 18 | 19 | ## Getting Started 20 | 21 | 1. **Clone the Repository:** 22 | ```bash 23 | git clone https://github.com/Preparation-Street/Programming-Street-150.git 24 | ``` 25 | Thank you for contributing to our repository. Your participation helps us grow and provide valuable resources to the community. 26 | 27 | Happy coding! 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programming Street - 150 2 | Starting from Zero in Coding - DSA is a critical Problem-Solving Skill, it's important to build a strong foundation before diving into it. 3 | 4 | #### [Programming Street - 150 Feedback Form](https://forms.gle/aHqtQLzw7C7tscgXA) 5 | #### [All Important Links](https://linktr.ee/linkszone) 6 | 7 | #### Video 🎥 - Click on the Img 👇 8 | [![Watch the video](https://github.com/user-attachments/assets/77812dca-b9ac-4598-8831-c253789e5781)](https://www.youtube.com/watch?v=f-CTHI3xl74) 9 | 10 | For those coming from a non-technical background, the world of coding can seem daunting, especially when faced with advanced concepts like Data Structures and Algorithms (DSA). 11 | 12 | While DSA is a critical Problem-Solving Skill, it's important to build a strong foundation before diving into it. 13 | 14 | **Programming Street - 150** is a collection of 150 curated problems focusing on building foundational programming skills. This collection is divided into three different sprints: 15 | 16 | 1. **PS-Sprint-1**: This sprint covers fundamental problems to help you build your basic programming skills. 17 | 18 | 2. **PS-Sprint-2**: This sprint focuses on intermediate-level problems, further strengthening your foundational skills and introducing more complex concepts. 19 | 20 | 3. **PS-Sprint-3**: This sprint includes advanced problems designed to solidify your understanding and prepare you for more challenging programming tasks. 21 | 22 | ## The Right Starting Point 23 | 24 | 1. Select a Programming Language: Begin with a language that suits your interests or industry needs Python, Java, or C++. Focus on mastering the fundamentals: syntax, control structures (loops, conditionals), variables, data types, and other core concepts. 25 | 26 | These are the building blocks of your coding journey. 27 | 28 | 2. Practice Essential Problems: Once you’ve gained confidence in the basics, it's time to apply your knowledge by solving fundamental programming challenges. Aim to complete at least 100 to 150 exercises, including: 29 | - Determining Even/Odd Numbers 30 | - Checking for Prime Numbers 31 | - Validating Leap Years 32 | - Calculating Armstrong Numbers 33 | - Generating the Fibonacci Series 34 | - Identifying Palindromes 35 | - Crafting Star Patterns 36 | - Tackling Basic Mathematical and Logical Problems ( And Many More....... ) 37 | 38 | These exercises may seem straightforward, but they are crucial for strengthening your understanding of programming logic and syntax. A solid grasp of these fundamentals will provide the stability you need to excel in more complex areas. 39 | 40 | I'm curating a list of 150 essential programming problems designed to help you establish a robust foundational skill set. This carefully selected list will be a valuable resource for anyone starting their coding journey, offering a structured path to developing strong, fundamental programming skills. 41 | 42 | ![Progamming Street - 150 (1)](https://github.com/user-attachments/assets/5770ae88-fd83-4c86-8588-6aa00ab20e6a) 43 | 44 | 45 | -------------------------------------------------------------------------------- /PS-Sprint-3/README.md: -------------------------------------------------------------------------------- 1 | ### **Problem 1: Print a Right-Angle Triangle of Stars** 2 | **Difficulty:** Easy 3 | **Topics:** Pattern Printing 4 | **Hint:** Print a right-angle triangle pattern of stars (`*`). Each row should contain an increasing number of stars, starting from 1 star in the first row. 5 | 6 | **Example 1:** 7 | **Input:** `n = 4` 8 | **Output:** 9 | ``` 10 | * 11 | ** 12 | *** 13 | **** 14 | ``` 15 | 16 | --- 17 | 18 | ### **Problem 2: Print a Square of Stars** 19 | **Difficulty:** Easy 20 | **Topics:** Pattern Printing 21 | **Hint:** Print a square pattern of stars (`*`). Each row and column should have the same number of stars. 22 | 23 | **Example 1:** 24 | **Input:** `n = 5` 25 | **Output:** 26 | ``` 27 | ***** 28 | ***** 29 | ***** 30 | ***** 31 | ***** 32 | ``` 33 | 34 | --- 35 | 36 | ### **Problem 3: Print a Pyramid Pattern** 37 | **Difficulty:** Easy 38 | **Topics:** Pattern Printing 39 | **Hint:** Print a pyramid pattern with stars (`*`). The pyramid should have a single peak and each row should have an increasing number of stars, centered horizontally. 40 | 41 | **Example 1:** 42 | **Input:** `n = 3` 43 | **Output:** 44 | ``` 45 | * 46 | *** 47 | ***** 48 | ``` 49 | 50 | --- 51 | 52 | ### **Problem 4: Print a Diamond Pattern** 53 | **Difficulty:** Easy 54 | **Topics:** Pattern Printing 55 | **Hint:** Print a diamond pattern with stars (`*`). The pattern should include a single peak in the middle with symmetric rows above and below it. 56 | 57 | **Example 1:** 58 | **Input:** `n = 3` 59 | **Output:** 60 | ``` 61 | * 62 | *** 63 | ***** 64 | *** 65 | * 66 | ``` 67 | 68 | --- 69 | 70 | ### **Problem 5: Print a Hollow Square of Stars** 71 | **Difficulty:** Easy 72 | **Topics:** Pattern Printing 73 | **Hint:** Print a hollow square pattern with stars (`*`). The border of the square should be filled with stars while the inner part should be empty. 74 | 75 | **Example 1:** 76 | **Input:** `n = 5` 77 | **Output:** 78 | ``` 79 | ***** 80 | * * 81 | * * 82 | * * 83 | ***** 84 | ``` 85 | 86 | ### **Problem 6: Print a Number Triangle** 87 | **Difficulty:** Easy 88 | **Topics:** Pattern Printing 89 | **Hint:** Print a right-angle triangle pattern with numbers. Each row should contain an increasing sequence of numbers starting from 1. 90 | 91 | **Example 1:** 92 | **Input:** `n = 4` 93 | **Output:** 94 | ``` 95 | 1 96 | 12 97 | 123 98 | 1234 99 | ``` 100 | 101 | --- 102 | 103 | ### **Problem 7: Print an Inverted Triangle Pattern** 104 | **Difficulty:** Easy 105 | **Topics:** Pattern Printing 106 | **Hint:** Print an inverted triangle pattern with stars (`*`). Each row should contain decreasing numbers of stars from the top row. 107 | 108 | **Example 1:** 109 | **Input:** `n = 5` 110 | **Output:** 111 | ``` 112 | ***** 113 | **** 114 | *** 115 | ** 116 | * 117 | ``` 118 | 119 | --- 120 | 121 | ### **Problem 8: Print a Diamond Pattern with Numbers** 122 | **Difficulty:** Easy 123 | **Topics:** Pattern Printing 124 | **Hint:** Print a diamond pattern with numbers. The pattern should have a peak in the middle with symmetric rows above and below it. 125 | 126 | **Example 1:** 127 | **Input:** `n = 3` 128 | **Output:** 129 | ``` 130 | 1 131 | 121 132 | 12321 133 | 121 134 | 1 135 | ``` 136 | 137 | --- 138 | 139 | ### **Problem 9: Print a Right-Angle Triangle of Numbers** 140 | **Difficulty:** Easy 141 | **Topics:** Pattern Printing 142 | **Hint:** Print a right-angle triangle pattern with increasing numbers. Each row should contain a continuous sequence of increasing numbers. 143 | 144 | **Example 1:** 145 | **Input:** `n = 4` 146 | **Output:** 147 | ``` 148 | 1 149 | 23 150 | 456 151 | 78910 152 | ``` 153 | 154 | --- 155 | 156 | ### **Problem 10: Print a Pyramid Pattern with Numbers** 157 | **Difficulty:** Easy 158 | **Topics:** Pattern Printing 159 | **Hint:** Print a pyramid pattern with increasing numbers. Each row should have an increasing sequence of numbers, centered horizontally. 160 | 161 | **Example 1:** 162 | **Input:** `n = 3` 163 | **Output:** 164 | ``` 165 | 1 166 | 232 167 | 34543 168 | ``` 169 | 170 | --- 171 | 172 | ### **Problem 11: Print a Pattern of Alternating 0s and 1s** 173 | **Difficulty:** Medium 174 | **Topics:** Matrix Pattern 175 | **Hint:** Print a matrix where elements alternate between `0` and `1`. The pattern should alternate both row-wise and column-wise. 176 | 177 | **Example 1:** 178 | **Input:** `n = 4` 179 | **Output:** 180 | ``` 181 | 0101 182 | 1010 183 | 0101 184 | 1010 185 | ``` 186 | 187 | --- 188 | 189 | ### **Problem 12: Print a Pascal’s Triangle** 190 | **Difficulty:** Medium 191 | **Topics:** Matrix Pattern 192 | **Hint:** Print Pascal’s Triangle up to `N` rows. Each row should be constructed based on the sum of the elements directly above it in the previous row. 193 | 194 | **Example 1:** 195 | **Input:** `n = 4` 196 | **Output:** 197 | ``` 198 | 1 199 | 1 1 200 | 1 2 1 201 | 1 3 3 1 202 | ``` 203 | 204 | --- 205 | 206 | ### **Problem 13: Print a Pattern of Consecutive Numbers** 207 | **Difficulty:** Medium 208 | **Topics:** Matrix Pattern 209 | **Hint:** Print a matrix of consecutive numbers starting from 1, filling rows sequentially. 210 | 211 | **Example 1:** 212 | **Input:** `n = 3` 213 | **Output:** 214 | ``` 215 | 1 2 3 216 | 4 5 6 217 | 7 8 9 218 | ``` 219 | 220 | --- 221 | 222 | ### **Problem 14: Print a Star Pattern with Increasing Width** 223 | **Difficulty:** Medium 224 | **Topics:** Pattern Printing 225 | **Hint:** Print a pattern where each row has an increasing width of stars. 226 | 227 | **Example 1:** 228 | **Input:** `n = 3` 229 | **Output:** 230 | ``` 231 | * 232 | *** 233 | ***** 234 | ``` 235 | 236 | --- 237 | 238 | ### **Problem 15: Print a Right-Angle Triangle Pattern with Characters** 239 | **Difficulty:** Medium 240 | **Topics:** Pattern Printing 241 | **Hint:** Print a right-angle triangle pattern using characters. Each row should contain the same character repeated according to the row number. 242 | 243 | **Example 1:** 244 | **Input:** `n = 3` 245 | **Output:** 246 | ``` 247 | A 248 | BB 249 | CCC 250 | ``` 251 | 252 | --- 253 | 254 | ### **Problem 16: Print a Checkerboard Pattern** 255 | **Difficulty:** Medium 256 | **Topics:** Matrix Pattern 257 | **Hint:** Print a checkerboard pattern with two different characters alternating. 258 | 259 | **Example 1:** 260 | **Input:** `n = 4` 261 | **Output:** 262 | ``` 263 | XOXOXO 264 | OXOXOX 265 | XOXOXO 266 | OXOXOX 267 | ``` 268 | 269 | --- 270 | 271 | ### **Problem 17: Print a Pyramid Pattern of Increasing Stars** 272 | **Difficulty:** Medium 273 | **Topics:** Pattern Printing 274 | **Hint:** Print a pyramid pattern where each row increases in the number of stars. 275 | 276 | **Example 1:** 277 | **Input:** `n = 3` 278 | **Output:** 279 | ``` 280 | * 281 | *** 282 | ***** 283 | ``` 284 | 285 | --- 286 | 287 | ### **Problem 18: Print a Border Pattern with Numbers** 288 | **Difficulty:** Medium 289 | **Topics:** Matrix Pattern 290 | **Hint:** Print a border pattern using numbers. The border should be filled with numbers, and the inner part should be empty. 291 | 292 | **Example 1:** 293 | **Input:** `n = 4` 294 | **Output:** 295 | ``` 296 | 1234 297 | 1 1 298 | 1 1 299 | 1234 300 | ``` 301 | 302 | --- 303 | 304 | ### **Problem 19: Print an Inverted Pyramid Pattern with Characters** 305 | **Difficulty:** Medium 306 | **Topics:** Pattern Printing 307 | **Hint:** Print an inverted pyramid pattern using characters. Each row should have decreasing characters from the top row. 308 | 309 | **Example 1:** 310 | **Input:** `n = 3` 311 | **Output:** 312 | ``` 313 | CCC 314 | BB 315 | A 316 | ``` 317 | 318 | --- 319 | 320 | ### **Problem 20: Print a Cross Pattern with Stars** 321 | **Difficulty:** Medium 322 | **Topics:** Pattern Printing 323 | **Hint:** Print a cross pattern using stars. The cross should be centered within a matrix. 324 | 325 | **Example 1:** 326 | **Input:** `n = 5` 327 | **Output:** 328 | ``` 329 | *** 330 | * 331 | * 332 | * 333 | *** 334 | ``` 335 | 336 | --- 337 | 338 | ### **Problem 21: Print a Spiral Matrix** 339 | **Difficulty:** Hard 340 | **Topics:** Matrix Pattern 341 | **Hint:** Print a matrix filled with numbers in a spiral pattern. The numbers should start from 1 and increment as you move around the spiral. 342 | 343 | **Example 1:** 344 | **Input:** `n = 3` 345 | **Output:** 346 | ``` 347 | 1 2 3 348 | 8 9 4 349 | 7 6 5 350 | ``` 351 | 352 | --- 353 | 354 | ### **Problem 22: Print a Diamond Pattern with Increasing Width** 355 | **Difficulty:** Hard 356 | **Topics:** Pattern Printing 357 | **Hint:** Print a diamond pattern where each line has increasing width of stars. 358 | 359 | **Example 1:** 360 | **Input:** `n = 3` 361 | **Output:** 362 | ``` 363 | * 364 | *** 365 | ***** 366 | *** 367 | * 368 | ``` 369 | 370 | --- 371 | 372 | ### **Problem 23: Print a Diamond Pattern with Numbers Increasing** 373 | **Difficulty:** Hard 374 | **Topics:** Pattern Printing 375 | **Hint:** Print a diamond pattern where numbers increase. Each row should show a symmetrical pattern with numbers increasing towards the center. 376 | 377 | **Example 1:** 378 | **Input:** `n = 3` 379 | **Output:** 380 | ``` 381 | 1 382 | 121 383 | 12321 384 | 121 385 | 1 386 | ``` 387 | 388 | --- 389 | 390 | ### **Problem 24: Print a Pattern of Increasing and Decreasing Stars** 391 | **Difficulty:** Hard 392 | **Topics:** Pattern Printing 393 | **Hint:** Print a pattern where stars increase to a midpoint and then decrease. 394 | 395 | **Example 1:** 396 | **Input:** `n = 3` 397 | **Output:** 398 | ``` 399 | * 400 | *** 401 | ***** 402 | *** 403 | * 404 | ``` 405 | 406 | --- 407 | 408 | ### **Problem 25: Print a Matrix with Zigzag Pattern** 409 | **Difficulty:** Hard 410 | **Topics:** Matrix Pattern 411 | **Hint:** Print a matrix with a zigzag pattern of numbers. The numbers should alternate direction row-wise. 412 | 413 | **Example 1:** 414 | **Input:** `n = 3` 415 | **Output:** 416 | ``` 417 | 1 2 3 4 418 | 8 7 6 5 419 | 9 10 11 12 420 | ``` 421 | 422 | --- 423 | 424 | ### **Problem 26: Print a Pattern of Alternating Characters in Rows** 425 | **Difficulty:** Hard 426 | **Topics:** Pattern Printing 427 | **Hint:** Print a pattern where rows alternate between two characters. 428 | 429 | **Example 1:** 430 | **Input:** `n = 4` 431 | **Output:** 432 | ``` 433 | ABAB 434 | BABA 435 | ABAB 436 | BABA 437 | ``` 438 | 439 | --- 440 | 441 | ### **Problem 27: Print a Number Pyramid Pattern with Characters** 442 | **Difficulty:** Hard 443 | **Topics:** Pattern Printing 444 | **Hint:** Print a pyramid pattern using increasing characters, where each row increases in width and character range. 445 | 446 | **Example 1:** 447 | **Input:** `n = 3` 448 | **Output:** 449 | ``` 450 | A 451 | BCD 452 | EFGHI 453 | ``` 454 | 455 | --- 456 | 457 | ### **Problem 28: Print a Pattern with Diagonal Lines** 458 | **Difficulty:** Hard 459 | **Topics:** Pattern Printing 460 | **Hint:** Print a pattern with diagonal lines using characters. Each diagonal line should be aligned properly. 461 | 462 | **Example 1:** 463 | **Input:** `n = 4` 464 | **Output:** 465 | ``` 466 | A 467 | B B 468 | C C 469 | D D 470 | ``` 471 | 472 | --- 473 | 474 | ### **Problem 29: Print a Matrix with Diamond Pattern of Numbers** 475 | **Difficulty:** Hard 476 | **Topics:** Matrix Pattern 477 | **Hint:** Print a matrix where elements follow a diamond pattern with numbers. 478 | 479 | **Example 1:** 480 | **Input:** `n = 3` 481 | **Output:** 482 | ``` 483 | 1 484 | 121 485 | 12321 486 | 121 487 | 1 488 | ``` 489 | 490 | --- 491 | 492 | ### **Problem 30: Print a Cross Pattern of Stars with Diagonals** 493 | **Difficulty:** Hard 494 | **Topics:** Pattern Printing 495 | **Hint:** Print a cross pattern using stars with intersecting diagonals. 496 | 497 | **Example 1:** 498 | **Input:** `n = 5` 499 | **Output:** 500 | ``` 501 | * * * * * 502 | * * * * 503 | * * * 504 | * * 505 | * 506 | * * 507 | * * * 508 | * * * * 509 | * * * * * 510 | ``` 511 | 512 | ### **Problem 31: Print a Triangular Matrix with Numbers** 513 | **Difficulty:** Easy 514 | **Topics:** Pattern Printing 515 | **Hint:** Print a triangular matrix where each row contains increasing numbers. Each subsequent row should start from the next number. 516 | 517 | **Example 1:** 518 | **Input:** `n = 3` 519 | **Output:** 520 | ``` 521 | 1 522 | 2 3 523 | 4 5 6 524 | ``` 525 | 526 | --- 527 | 528 | ### **Problem 32: Print a Star Pattern with Increasing and Decreasing Width** 529 | **Difficulty:** Medium 530 | **Topics:** Pattern Printing 531 | **Hint:** Print a pattern with stars that increase to a midpoint and then decrease. The stars should be centered horizontally. 532 | 533 | **Example 1:** 534 | **Input:** `n = 3` 535 | **Output:** 536 | ``` 537 | * 538 | *** 539 | ***** 540 | *** 541 | * 542 | ``` 543 | 544 | --- 545 | 546 | ### **Problem 33: Print a Pattern of Nested Squares** 547 | **Difficulty:** Medium 548 | **Topics:** Pattern Printing 549 | **Hint:** Print a pattern with nested squares using stars. The outermost square should be filled with stars, and each subsequent square should be smaller and centered inside the previous one. 550 | 551 | **Example 1:** 552 | **Input:** `n = 5` 553 | **Output:** 554 | ``` 555 | ***** 556 | * * 557 | * * 558 | * * 559 | ***** 560 | ``` 561 | 562 | --- 563 | 564 | ### **Problem 34: Print a Pattern with Increasing Characters in Columns** 565 | **Difficulty:** Medium 566 | **Topics:** Pattern Printing 567 | **Hint:** Print a pattern where each column contains increasing characters from `A`. 568 | 569 | **Example 1:** 570 | **Input:** `n = 3` 571 | **Output:** 572 | ``` 573 | A 574 | B C 575 | D E F 576 | ``` 577 | 578 | --- 579 | 580 | ### **Problem 35: Print a Matrix with Spiral Diagonals** 581 | **Difficulty:** Hard 582 | **Topics:** Matrix Pattern 583 | **Hint:** Print a matrix with numbers arranged in diagonal spirals. The numbers should fill the matrix in a diagonal spiral fashion. 584 | 585 | **Example 1:** 586 | **Input:** `n = 3` 587 | **Output:** 588 | ``` 589 | 1 2 3 590 | 4 5 6 591 | 7 8 9 592 | ``` 593 | 594 | --- 595 | 596 | ### **Problem 36: Print a Checkerboard Pattern with Increasing Size** 597 | **Difficulty:** Medium 598 | **Topics:** Pattern Printing 599 | **Hint:** Print a checkerboard pattern where the size of each square increases as you move along the matrix. 600 | 601 | **Example 1:** 602 | **Input:** `n = 3` 603 | **Output:** 604 | ``` 605 | XOX 606 | OXO 607 | XOX 608 | ``` 609 | 610 | --- 611 | 612 | ### **Problem 37: Print a Cross Pattern with Increasing Size** 613 | **Difficulty:** Medium 614 | **Topics:** Pattern Printing 615 | **Hint:** Print a cross pattern where the size of the cross increases with each row. The pattern should be centered. 616 | 617 | **Example 1:** 618 | **Input:** `n = 3` 619 | **Output:** 620 | ``` 621 | * 622 | *** 623 | ***** 624 | *** 625 | * 626 | ``` 627 | 628 | --- 629 | 630 | ### **Problem 38: Print a Pattern of Alternating Triangles** 631 | **Difficulty:** Medium 632 | **Topics:** Pattern Printing 633 | **Hint:** Print a pattern with alternating triangles of stars. The triangles should alternate direction. 634 | 635 | **Example 1:** 636 | **Input:** `n = 3` 637 | **Output:** 638 | ``` 639 | * 640 | *** 641 | ***** 642 | *** 643 | * 644 | ``` 645 | 646 | --- 647 | 648 | ### **Problem 39: Print a Matrix with Diamond Pattern of Numbers** 649 | **Difficulty:** Medium 650 | **Topics:** Pattern Printing 651 | **Hint:** Print a matrix where numbers form a diamond pattern. The numbers should increase and decrease symmetrically around the center. 652 | 653 | **Example 1:** 654 | **Input:** `n = 3` 655 | **Output:** 656 | ``` 657 | 1 658 | 121 659 | 12321 660 | 121 661 | 1 662 | ``` 663 | 664 | --- 665 | 666 | ### **Problem 40: Print a Star Pattern with Increasing Width and Centered** 667 | **Difficulty:** Medium 668 | **Topics:** Pattern Printing 669 | **Hint:** Print a pattern where the width of stars increases, and the stars are centered horizontally. 670 | 671 | **Example 1:** 672 | **Input:** `n = 3` 673 | **Output:** 674 | ``` 675 | * 676 | *** 677 | ***** 678 | ``` 679 | 680 | --- 681 | 682 | ### **Problem 41: Print a Pattern with Spiral and Zigzag** 683 | **Difficulty:** Hard 684 | **Topics:** Matrix Pattern 685 | **Hint:** Print a matrix with both spiral and zigzag patterns. The matrix should first fill in a spiral pattern and then in a zigzag fashion. 686 | 687 | **Example 1:** 688 | **Input:** `n = 3` 689 | **Output:** 690 | ``` 691 | 1 2 3 692 | 6 5 4 693 | 7 8 9 694 | ``` 695 | 696 | --- 697 | 698 | ### **Problem 42: Print a Pattern of Alternating Characters in Matrix** 699 | **Difficulty:** Medium 700 | **Topics:** Pattern Printing 701 | **Hint:** Print a matrix where characters alternate in each cell to form a pattern. 702 | 703 | **Example 1:** 704 | **Input:** `n = 3` 705 | **Output:** 706 | ``` 707 | ABAB 708 | BABA 709 | ABAB 710 | ``` 711 | 712 | --- 713 | 714 | ### **Problem 43: Print a Pattern with Nested Triangles** 715 | **Difficulty:** Medium 716 | **Topics:** Pattern Printing 717 | **Hint:** Print a pattern with nested triangles of stars. Each triangle should be centered and decrease in size. 718 | 719 | **Example 1:** 720 | **Input:** `n = 3` 721 | **Output:** 722 | ``` 723 | * 724 | *** 725 | ***** 726 | *** 727 | * 728 | ``` 729 | 730 | --- 731 | 732 | ### **Problem 44: Print a Matrix with Increasing Rows and Columns** 733 | **Difficulty:** Easy 734 | **Topics:** Matrix Pattern 735 | **Hint:** Print a matrix where each row and column contains increasing numbers. 736 | 737 | **Example 1:** 738 | **Input:** `n = 3` 739 | **Output:** 740 | ``` 741 | 1 2 3 742 | 4 5 6 743 | 7 8 9 744 | ``` 745 | 746 | --- 747 | 748 | ### **Problem 45: Print a Pattern with Rows of Increasing Characters** 749 | **Difficulty:** Medium 750 | **Topics:** Pattern Printing 751 | **Hint:** Print a pattern where each row contains an increasing sequence of characters. 752 | 753 | **Example 1:** 754 | **Input:** `n = 3` 755 | **Output:** 756 | ``` 757 | A 758 | BC 759 | DEF 760 | ``` 761 | 762 | --- 763 | 764 | ### **Problem 46: Print a Star Pattern with Diamond Shape and Numbers** 765 | **Difficulty:** Medium 766 | **Topics:** Pattern Printing 767 | **Hint:** Print a pattern with a diamond shape of stars, with numbers inside the diamond. 768 | 769 | **Example 1:** 770 | **Input:** `n = 3` 771 | **Output:** 772 | ``` 773 | 1 774 | 121 775 | 12321 776 | 121 777 | 1 778 | ``` 779 | 780 | --- 781 | 782 | ### **Problem 47: Print a Matrix with Cross Pattern of Numbers** 783 | **Difficulty:** Hard 784 | **Topics:** Matrix Pattern 785 | **Hint:** Print a matrix where the center forms a cross pattern with numbers. 786 | 787 | **Example 1:** 788 | **Input:** `n = 5` 789 | **Output:** 790 | ``` 791 | 12321 792 | 01210 793 | 01210 794 | 01210 795 | 12321 796 | ``` 797 | 798 | --- 799 | 800 | ### **Problem 48: Print a Pattern with Concentric Squares** 801 | **Difficulty:** Medium 802 | **Topics:** Pattern Printing 803 | **Hint:** Print a pattern with concentric squares using stars. The outer square should be larger and each subsequent square should be centered inside. 804 | 805 | **Example 1:** 806 | **Input:** `n = 5` 807 | **Output:** 808 | ``` 809 | ***** 810 | * * 811 | * * 812 | * * 813 | ***** 814 | ``` 815 | 816 | --- 817 | 818 | ### **Problem 49: Print a Pattern of Alternating Rows and Columns of Numbers** 819 | **Difficulty:** Easy 820 | **Topics:** Pattern Printing 821 | **Hint:** Print a pattern with alternating rows and columns of numbers, where each row and column increases sequentially. 822 | 823 | **Example 1:** 824 | **Input:** `n = 3` 825 | **Output:** 826 | ``` 827 | 123 828 | 456 829 | 789 830 | ``` 831 | 832 | --- 833 | 834 | ### **Problem 50: Print a Matrix with Zigzag Pattern of Stars** 835 | **Difficulty:** Medium 836 | **Topics:** Pattern Printing 837 | **Hint:** Print a matrix where stars form a zigzag pattern, alternating rows in their positioning. 838 | 839 | **Example 1:** 840 | **Input:** `n = 3` 841 | **Output:** 842 | ``` 843 | * * * 844 | * * 845 | * * * 846 | ``` -------------------------------------------------------------------------------- /PS-Sprint-2/README.md: -------------------------------------------------------------------------------- 1 | 1. **Finding the Sum of Digits of a Number Until Zero** 2 | **Difficulty**: Easy 3 | **Topics**: Basic Programming, Mathematical Computations 4 | **Description**: Write a program to repeatedly sum the digits of a number until the result is zero. 5 | **Example**: 6 | Input: `number = 123` 7 | Output: `6` 8 | Explanation: Sum of digits is 1 + 2 + 3 = 6; sum of digits of 6 is 6 (which is a single digit). 9 | 10 | 2. **Generating a Multiplication Table for a Range** 11 | **Difficulty**: Easy 12 | **Topics**: Arrays, Basic Programming 13 | **Description**: Write a program to generate multiplication tables for numbers within a specified range. 14 | **Example**: 15 | Input: `start = 2`, `end = 4` 16 | Output: 17 | ``` 18 | 2 x 1 = 2 3 x 1 = 3 4 x 1 = 4 19 | 2 x 2 = 4 3 x 2 = 6 4 x 2 = 8 20 | 2 x 3 = 6 3 x 3 = 9 4 x 3 = 12 21 | 2 x 4 = 8 3 x 4 = 12 4 x 4 = 16 22 | ``` 23 | 24 | 3. **Calculating the Sum of a Series (1 + 1/2 + 1/3 + ... + 1/n)** 25 | **Difficulty**: Medium 26 | **Topics**: Mathematical Computations 27 | **Description**: Write a program to calculate the sum of the series 1 + 1/2 + 1/3 + ... + 1/n up to the nth term. 28 | **Example**: 29 | Input: `n = 4` 30 | Output: `2.083333` 31 | Explanation: Sum of the series is 1 + 1/2 + 1/3 + 1/4 ≈ 2.083333. 32 | 33 | 4. **Finding All Pairs of Elements in an Array that Add Up to a Given Sum** 34 | **Difficulty**: Medium 35 | **Topics**: Arrays, Hashing 36 | **Description**: Write a program to find all pairs of elements in an array whose sum equals a specified target. 37 | **Example**: 38 | Input: `array = [1, 2, 3, 4, 5]`, `target = 5` 39 | Output: `[(1, 4), (2, 3)]` 40 | Explanation: Pairs that sum up to 5 are (1, 4) and (2, 3). 41 | 42 | 5. **Generating a Diamond Pattern of Stars** 43 | **Difficulty**: Medium 44 | **Topics**: Patterns, Basic Programming 45 | **Description**: Write a program to create a diamond pattern with stars of a given size. 46 | **Example**: 47 | Input: `size = 5` 48 | Output: 49 | ``` 50 | * 51 | *** 52 | ***** 53 | *** 54 | * 55 | ``` 56 | 57 | 6. **Counting the Number of Palindromic Substrings in a String** 58 | **Difficulty**: Medium 59 | **Topics**: String Manipulation 60 | **Description**: Write a program to count how many palindromic substrings exist in a given string. 61 | **Example**: 62 | Input: `string = "aaa"` 63 | Output: `6` 64 | Explanation: Palindromic substrings are "a", "a", "a", "aa", "aa", "aaa". 65 | 66 | 7. **Generating a Matrix with Multiplication Table** 67 | **Difficulty**: Easy 68 | **Topics**: Arrays, Matrix Operations 69 | **Description**: Write a program to generate a matrix where each element at position (i, j) is the product of i and j. 70 | **Example**: 71 | Input: `size = 3` 72 | Output: 73 | ``` 74 | 1 2 3 75 | 2 4 6 76 | 3 6 9 77 | ``` 78 | 79 | 8. **Finding the GCD of Multiple Numbers** 80 | **Difficulty**: Medium 81 | **Topics**: Mathematical Computations 82 | **Description**: Write a program to find the GCD (Greatest Common Divisor) of an array of numbers. 83 | **Example**: 84 | Input: `array = [12, 24, 36]` 85 | Output: `12` 86 | Explanation: The GCD of 12, 24, and 36 is 12. 87 | 88 | 9. **Finding the Sum of the First N Odd Numbers** 89 | **Difficulty**: Easy 90 | **Topics**: Mathematical Computations 91 | **Description**: Write a program to calculate the sum of the first N odd numbers. 92 | **Example**: 93 | Input: `N = 5` 94 | Output: `25` 95 | Explanation: Sum of the first 5 odd numbers (1 + 3 + 5 + 7 + 9) is 25. 96 | 97 | 10. **Finding the Number of Perfect Numbers Up to a Given Limit** 98 | **Difficulty**: Medium 99 | **Topics**: Number Theory 100 | **Description**: Write a program to find how many perfect numbers exist up to a given limit. 101 | **Example**: 102 | Input: `limit = 30` 103 | Output: `1` 104 | Explanation: There is only one perfect number (6) up to 30. 105 | 106 | 11. **Finding the Largest Prime Factor of a Number** 107 | **Difficulty**: Medium 108 | **Topics**: Number Theory 109 | **Description**: Write a program to find the largest prime factor of a given number. 110 | **Example**: 111 | Input: `number = 28` 112 | Output: `7` 113 | Explanation: The prime factors of 28 are 2 and 7, with the largest being 7. 114 | 115 | 12. **Generating a Matrix of Fibonacci Numbers** 116 | **Difficulty**: Medium 117 | **Topics**: Arrays, Matrix Operations 118 | **Description**: Write a program to generate a matrix where each element is a Fibonacci number. 119 | **Example**: 120 | Input: `size = 3` 121 | Output: 122 | ``` 123 | 1 1 2 124 | 3 5 8 125 | 13 21 34 126 | ``` 127 | 128 | 13. **Finding the Sum of the First N Prime Numbers** 129 | **Difficulty**: Medium 130 | **Topics**: Prime Numbers, Mathematical Computations 131 | **Description**: Write a program to calculate the sum of the first N prime numbers. 132 | **Example**: 133 | Input: `N = 4` 134 | Output: `17` 135 | Explanation: The sum of the first 4 prime numbers (2 + 3 + 5 + 7) is 17. 136 | 137 | 14. **Checking for a Balanced Bracket Sequence** 138 | **Difficulty**: Medium 139 | **Topics**: String Manipulation, Stack 140 | **Description**: Write a program to check if a given string with brackets is balanced. 141 | **Example**: 142 | Input: `string = "{[()]}"` 143 | Output: `True` 144 | Explanation: The brackets are balanced. 145 | 146 | 15. **Finding the Sum of Numbers in a String** 147 | **Difficulty**: Easy 148 | **Topics**: String Manipulation 149 | **Description**: Write a program to extract and sum all numbers present in a given string. 150 | **Example**: 151 | Input: `string = "The numbers are 12 and 34"` 152 | Output: `46` 153 | Explanation: The sum of numbers 12 and 34 is 46. 154 | 155 | 16. **Finding the Longest Consecutive Sequence in an Array** 156 | **Difficulty**: Medium 157 | **Topics**: Arrays, Hashing 158 | **Description**: Write a program to find the longest sequence of consecutive numbers in an array. 159 | **Example**: 160 | Input: `array = [100, 4, 200, 1, 3, 2]` 161 | Output: `4` 162 | Explanation: The longest consecutive sequence is [1, 2, 3, 4]. 163 | 164 | 17. **Generating a Matrix with a Spiral Pattern** 165 | **Difficulty**: Medium 166 | **Topics**: Arrays, Matrix Operations 167 | **Description**: Write a program to generate a matrix filled with numbers in a spiral pattern. 168 | **Example**: 169 | Input: `size = 3` 170 | Output: 171 | ``` 172 | 1 2 3 173 | 8 9 4 174 | 7 6 5 175 | ``` 176 | 177 | 18. **Finding All Subsets of a Set** 178 | **Difficulty**: Medium 179 | **Topics**: Combinatorics 180 | **Description**: Write a program to generate all possible subsets of a given set of numbers. 181 | **Example**: 182 | Input: `set = [1, 2]` 183 | Output: `[[], [1], [2], [1, 2]]` 184 | Explanation: The subsets of [1, 2] are the empty set, [1], [2], and [1, 2]. 185 | 186 | 19. **Checking for Perfect Squares in a Range** 187 | **Difficulty**: Easy 188 | **Topics**: Mathematical Comput 189 | 190 | ations 191 | **Description**: Write a program to check which numbers in a given range are perfect squares. 192 | **Example**: 193 | Input: `start = 1`, `end = 10` 194 | Output: `[1, 4, 9]` 195 | Explanation: Perfect squares between 1 and 10 are 1, 4, and 9. 196 | 197 | 20. **Finding the Sum of Diagonal Elements in a Matrix** 198 | **Difficulty**: Easy 199 | **Topics**: Matrix Operations 200 | **Description**: Write a program to calculate the sum of the diagonal elements in a square matrix. 201 | **Example**: 202 | Input: `matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]` 203 | Output: `15` 204 | Explanation: The sum of the diagonal elements (1 + 5 + 9) is 15. 205 | 206 | 21. **Finding the Second Smallest Number in an Array** 207 | **Difficulty**: Easy 208 | **Topics**: Arrays 209 | **Description**: Write a program to find the second smallest number in an array. 210 | **Example**: 211 | Input: `array = [12, 13, 1, 10, 34, 1]` 212 | Output: `10` 213 | Explanation: The second smallest number in the array is 10. 214 | 215 | 22. **Generating Pascal’s Triangle Up to N Rows** 216 | **Difficulty**: Medium 217 | **Topics**: Combinatorics 218 | **Description**: Write a program to generate Pascal’s Triangle up to N rows. 219 | **Example**: 220 | Input: `N = 3` 221 | Output: 222 | ``` 223 | 1 224 | 1 1 225 | 1 2 1 226 | ``` 227 | 228 | 23. **Finding the Sum of Digits of the Product of Two Numbers** 229 | **Difficulty**: Easy 230 | **Topics**: Mathematical Computations 231 | **Description**: Write a program to find the sum of the digits of the product of two given numbers. 232 | **Example**: 233 | Input: `number1 = 12`, `number2 = 34` 234 | Output: `9` 235 | Explanation: The product of 12 and 34 is 408, and the sum of its digits is 4 + 0 + 8 = 12. 236 | 237 | 24. **Checking for Palindromic Numbers in a Range** 238 | **Difficulty**: Medium 239 | **Topics**: Mathematical Computations 240 | **Description**: Write a program to check for palindromic numbers within a given range. 241 | **Example**: 242 | Input: `start = 1`, `end = 100` 243 | Output: `[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99]` 244 | Explanation: Palindromic numbers between 1 and 100 are the numbers listed. 245 | 246 | 25. **Generating a Matrix with Alternating 0s and 1s** 247 | **Difficulty**: Easy 248 | **Topics**: Arrays, Matrix Operations 249 | **Description**: Write a program to generate a matrix where the elements alternate between 0 and 1. 250 | **Example**: 251 | Input: `size = 3` 252 | Output: 253 | ``` 254 | 0 1 0 255 | 1 0 1 256 | 0 1 0 257 | ``` 258 | 259 | 26. **Finding the Count of a Specific Word in a String** 260 | **Difficulty**: Easy 261 | **Topics**: String Manipulation 262 | **Description**: Write a program to count how many times a specific word appears in a given string. 263 | **Example**: 264 | Input: `string = "hello world hello"` 265 | Output: `2` 266 | Explanation: The word "hello" appears 2 times in the string. 267 | 268 | 27. **Finding the Largest Sum of a Subarray** 269 | **Difficulty**: Medium 270 | **Topics**: Arrays, Dynamic Programming 271 | **Description**: Write a program to find the largest sum of any contiguous subarray. 272 | **Example**: 273 | Input: `array = [-2, 1, -3, 4, -1, 2, 1, -5, 4]` 274 | Output: `6` 275 | Explanation: The largest sum is 6, from the subarray `[4, -1, 2, 1]`. 276 | 277 | 28. **Generating a Right-Angle Triangle Pattern of Numbers** 278 | **Difficulty**: Easy 279 | **Topics**: Patterns 280 | **Description**: Write a program to create a right-angle triangle pattern with numbers. 281 | **Example**: 282 | Input: `height = 4` 283 | Output: 284 | ``` 285 | 1 286 | 12 287 | 123 288 | 1234 289 | ``` 290 | 291 | 29. **Finding All Divisors of the Product of Two Numbers** 292 | **Difficulty**: Medium 293 | **Topics**: Number Theory 294 | **Description**: Write a program to find all divisors of the product of two given numbers. 295 | **Example**: 296 | Input: `number1 = 6`, `number2 = 10` 297 | Output: `[1, 2, 3, 5, 6, 10, 15, 30]` 298 | Explanation: The product of 6 and 10 is 60, and its divisors are listed. 299 | 300 | 30. **Finding the Longest Sequence of Consecutive 1s in a Binary Array** 301 | **Difficulty**: Medium 302 | **Topics**: Arrays, Binary Operations 303 | **Description**: Write a program to find the longest sequence of consecutive 1s in a binary array. 304 | **Example**: 305 | Input: `array = [1, 1, 0, 1, 1, 1]` 306 | Output: `3` 307 | Explanation: The longest sequence of 1s is `[1, 1, 1]` with length 3. 308 | 309 | 31. **Calculating the Sum of the First N Fibonacci Numbers** 310 | **Difficulty**: Medium 311 | **Topics**: Fibonacci Sequence, Mathematical Computations 312 | **Description**: Write a program to calculate the sum of the first N Fibonacci numbers. 313 | **Example**: 314 | Input: `N = 5` 315 | Output: `12` 316 | Explanation: The first 5 Fibonacci numbers are 1, 1, 2, 3, 5, and their sum is 12. 317 | 318 | 32. **Checking for a Repeated Substring in a String** 319 | **Difficulty**: Medium 320 | **Topics**: String Manipulation 321 | **Description**: Write a program to check if a substring is repeated within a given string. 322 | **Example**: 323 | Input: `string = "abab"` 324 | Output: `True` 325 | Explanation: The substring "ab" is repeated. 326 | 327 | 33. **Finding the Median of a List of Numbers** 328 | **Difficulty**: Medium 329 | **Topics**: Sorting, Mathematical Computations 330 | **Description**: Write a program to find the median value of a list of numbers. 331 | **Example**: 332 | Input: `list = [3, 1, 4, 1, 5]` 333 | Output: `3` 334 | Explanation: After sorting the list to [1, 1, 3, 4, 5], the median is 3. 335 | 336 | 34. **Finding the Number of Words in a String** 337 | **Difficulty**: Easy 338 | **Topics**: String Manipulation 339 | **Description**: Write a program to count the number of words in a given string. 340 | **Example**: 341 | Input: `string = "Hello world"` 342 | Output: `2` 343 | Explanation: There are 2 words in the string. 344 | 345 | 35. **Generating a Matrix with a Diagonal Pattern** 346 | **Difficulty**: Medium 347 | **Topics**: Matrix Operations 348 | **Description**: Write a program to create a matrix where elements form diagonal lines of a given pattern. 349 | **Example**: 350 | Input: `size = 4` 351 | Output: 352 | ``` 353 | 1 0 0 0 354 | 1 1 0 0 355 | 1 1 1 0 356 | 1 1 1 1 357 | ``` 358 | 359 | 36. **Finding the Sum of the First N Even Numbers** 360 | **Difficulty**: Easy 361 | **Topics**: Mathematical Computations 362 | **Description**: Write a program to calculate the sum of the first N even numbers. 363 | **Example**: 364 | Input: `N = 4` 365 | Output: `20` 366 | Explanation: The first 4 even numbers are 2, 4, 6, 8, and their sum is 20. 367 | 368 | 37. **Finding the Count of Digits Greater Than a Specific Value** 369 | **Difficulty**: Easy 370 | **Topics**: Mathematical Computations 371 | **Description**: Write a program to count how many digits in a number are greater than a specific value. 372 | **Example**: 373 | Input: `number = 54321`, `value = 3` 374 | Output: `2` 375 | Explanation: The digits 376 | 377 | greater than 3 in 54321 are 5, 4, and 4, so the count is 2. 378 | 379 | 38. **Generating a Pattern of Prime Numbers** 380 | **Difficulty**: Medium 381 | **Topics**: Prime Numbers, Patterns 382 | **Description**: Write a program to generate a pattern where each row contains the first few prime numbers. 383 | **Example**: 384 | Input: `rows = 3` 385 | Output: 386 | ``` 387 | 2 388 | 2 3 389 | 2 3 5 390 | ``` 391 | 392 | 39. **Finding the Common Elements in Two Arrays** 393 | **Difficulty**: Medium 394 | **Topics**: Arrays 395 | **Description**: Write a program to find common elements between two arrays. 396 | **Example**: 397 | Input: `array1 = [1, 2, 3, 4]`, `array2 = [3, 4, 5, 6]` 398 | Output: `[3, 4]` 399 | Explanation: The common elements between the two arrays are 3 and 4. 400 | 401 | 40. **Finding the Sum of the Squares of All Even Numbers Up to N** 402 | **Difficulty**: Medium 403 | **Topics**: Mathematical Computations 404 | **Description**: Write a program to calculate the sum of squares of all even numbers up to a given N. 405 | **Example**: 406 | Input: `N = 4` 407 | Output: `20` 408 | Explanation: The even numbers up to 4 are 2 and 4, and their squares are 4 and 16. The sum is 20. 409 | 410 | 41. **Generating a Pattern of Increasing Numbers** 411 | **Difficulty**: Easy 412 | **Topics**: Patterns 413 | **Description**: Write a program to create a pattern where numbers increase with each row. 414 | **Example**: 415 | Input: `rows = 3` 416 | Output: 417 | ``` 418 | 1 419 | 12 420 | 123 421 | ``` 422 | 423 | 42. **Finding the Largest Element in Each Row of a Matrix** 424 | **Difficulty**: Easy 425 | **Topics**: Matrix Operations 426 | **Description**: Write a program to find the largest element in each row of a matrix. 427 | **Example**: 428 | Input: `matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]` 429 | Output: `[3, 6, 9]` 430 | Explanation: The largest elements in each row are 3, 6, and 9. 431 | 432 | 43. **Checking for Anagram Pairs in a List of Strings** 433 | **Difficulty**: Medium 434 | **Topics**: String Manipulation 435 | **Description**: Write a program to find pairs of strings in a list that are anagrams of each other. 436 | **Example**: 437 | Input: `strings = ["listen", "silent", "hello", "world"]` 438 | Output: `[("listen", "silent")]` 439 | Explanation: "listen" and "silent" are anagrams. 440 | 441 | 44. **Finding the Frequency of Each Character in a String** 442 | **Difficulty**: Easy 443 | **Topics**: String Manipulation 444 | **Description**: Write a program to count the frequency of each character in a given string. 445 | **Example**: 446 | Input: `string = "hello"` 447 | Output: `{'h': 1, 'e': 1, 'l': 2, 'o': 1}` 448 | Explanation: The frequency of each character in the string "hello" is shown. 449 | 450 | 45. **Generating a Matrix with Random Numbers** 451 | **Difficulty**: Easy 452 | **Topics**: Random Number Generation, Matrix Operations 453 | **Description**: Write a program to generate a matrix filled with random numbers. 454 | **Example**: 455 | Input: `rows = 2`, `columns = 3` 456 | Output: 457 | ``` 458 | 3 8 1 459 | 7 4 6 460 | ``` 461 | 462 | 46. **Finding the Length of the Longest Word in a String** 463 | **Difficulty**: Easy 464 | **Topics**: String Manipulation 465 | **Description**: Write a program to find the length of the longest word in a given string. 466 | **Example**: 467 | Input: `string = "Find the longest word"` 468 | Output: `8` 469 | Explanation: The longest word is "longest" with length 8. 470 | 471 | 47. **Finding All Triplets in an Array That Sum to Zero** 472 | **Difficulty**: Medium 473 | **Topics**: Arrays, Sorting 474 | **Description**: Write a program to find all unique triplets in an array that sum to zero. 475 | **Example**: 476 | Input: `array = [-1, 0, 1, 2, -1, -4]` 477 | Output: `[[-1, -1, 2], [-1, 0, 1]]` 478 | Explanation: The unique triplets that sum to zero are listed. 479 | 480 | 48. **Generating a Square Matrix with Random Values** 481 | **Difficulty**: Easy 482 | **Topics**: Random Number Generation, Matrix Operations 483 | **Description**: Write a program to generate a square matrix where each element is a random value. 484 | **Example**: 485 | Input: `size = 3` 486 | Output: 487 | ``` 488 | 7 3 5 489 | 2 6 9 490 | 1 8 4 491 | ``` 492 | 493 | 49. **Finding the Difference Between the Sum of Even and Odd Numbers in an Array** 494 | **Difficulty**: Easy 495 | **Topics**: Arrays, Mathematical Computations 496 | **Description**: Write a program to calculate the difference between the sum of even and odd numbers in an array. 497 | **Example**: 498 | Input: `array = [1, 2, 3, 4, 5, 6]` 499 | Output: `4` 500 | Explanation: The sum of even numbers is 12, and the sum of odd numbers is 8. The difference is 4. 501 | 502 | 50. **Generating a Triangle Pattern of Stars with a Given Height** 503 | **Difficulty**: Easy 504 | **Topics**: Patterns 505 | **Description**: Write a program to create a triangle pattern of stars with a specified height. 506 | **Example**: 507 | Input: `height = 4` 508 | Output: 509 | ``` 510 | * 511 | ** 512 | *** 513 | **** 514 | ``` -------------------------------------------------------------------------------- /PS-Sprint-1/README.md: -------------------------------------------------------------------------------- 1 | 1. **Determining Even/Odd Numbers** 2 | **Difficulty**: Easy 3 | **Topics**: Basic Programming 4 | **Description**: Write a program to check whether a number is even or odd. 5 | **Example**: 6 | Input: `number = 4` 7 | Output: `Even` 8 | Explanation: Since 4 is divisible by 2, it is an even number. 9 | 10 | 2. **Checking for Prime Numbers** 11 | **Difficulty**: Easy 12 | **Topics**: Basic Programming, Number Theory 13 | **Description**: Write a program to determine if a number is prime. 14 | **Example**: 15 | Input: `number = 7` 16 | Output: `Prime` 17 | Explanation: 7 has no divisors other than 1 and itself, so it is a prime number. 18 | 19 | 3. **Validating Leap Years** 20 | **Difficulty**: Easy 21 | **Topics**: Basic Programming, Date Handling 22 | **Description**: Write a program to check if a given year is a leap year. 23 | **Example**: 24 | Input: `year = 2020` 25 | Output: `Leap Year` 26 | Explanation: 2020 is divisible by 4 but not by 100, or it is divisible by 400, so it is a leap year. 27 | 28 | 4. **Calculating Armstrong Numbers** 29 | **Difficulty**: Easy 30 | **Topics**: Basic Programming, Number Theory 31 | **Description**: Write a program to check if a number is an Armstrong number. 32 | **Example**: 33 | Input: `number = 153` 34 | Output: `Armstrong Number` 35 | Explanation: 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. 36 | 37 | 5. **Generating the Fibonacci Series** 38 | **Difficulty**: Easy 39 | **Topics**: Basic Programming, Sequences 40 | **Description**: Write a program to generate the Fibonacci series up to a given number. 41 | **Example**: 42 | Input: `limit = 10` 43 | Output: `[0, 1, 1, 2, 3, 5, 8]` 44 | Explanation: The Fibonacci series up to 10 is generated as [0, 1, 1, 2, 3, 5, 8]. 45 | 46 | 6. **Identifying Palindromes** 47 | **Difficulty**: Easy 48 | **Topics**: Basic Programming, String Manipulation 49 | **Description**: Write a program to check if a string or number is a palindrome. 50 | **Example**: 51 | Input: `string = "radar"` 52 | Output: `Palindrome` 53 | Explanation: "radar" reads the same backward as forward. 54 | 55 | 7. **Crafting Star Patterns** 56 | **Difficulty**: Easy 57 | **Topics**: Basic Programming, Patterns 58 | **Description**: Write a program to create different star patterns (e.g., pyramid, diamond). 59 | **Example**: 60 | Input: `patternType = "pyramid", height = 5` 61 | Output: 62 | ``` 63 | * 64 | *** 65 | ***** 66 | ******* 67 | ********* 68 | ``` 69 | Explanation: A pyramid pattern with a height of 5 is generated. 70 | 71 | 8. **Finding the Factorial of a Number** 72 | **Difficulty**: Easy 73 | **Topics**: Basic Programming, Mathematical Computations 74 | **Description**: Write a program to compute the factorial of a given number. 75 | **Example**: 76 | Input: `number = 5` 77 | Output: `120` 78 | Explanation: 5! (factorial) is 5 × 4 × 3 × 2 × 1 = 120. 79 | 80 | 9. **Summing Digits of a Number** 81 | **Difficulty**: Easy 82 | **Topics**: Basic Programming, Mathematical Computations 83 | **Description**: Write a program to calculate the sum of digits of a number. 84 | **Example**: 85 | Input: `number = 1234` 86 | Output: `10` 87 | Explanation: The sum of the digits 1 + 2 + 3 + 4 = 10. 88 | 89 | 10. **Finding the Greatest Common Divisor (GCD)** 90 | **Difficulty**: Easy 91 | **Topics**: Basic Programming, Number Theory 92 | **Description**: Write a program to find the GCD of two numbers. 93 | **Example**: 94 | Input: `a = 48, b = 18` 95 | Output: `6` 96 | Explanation: The GCD of 48 and 18 is 6. 97 | 98 | 11. **Finding the Least Common Multiple (LCM)** 99 | **Difficulty**: Easy 100 | **Topics**: Basic Programming, Number Theory 101 | **Description**: Write a program to find the LCM of two numbers. 102 | **Example**: 103 | Input: `a = 12, b = 15` 104 | Output: `60` 105 | Explanation: The LCM of 12 and 15 is 60. 106 | 107 | 12. **Counting Vowels and Consonants in a String** 108 | **Difficulty**: Easy 109 | **Topics**: Basic Programming, String Manipulation 110 | **Description**: Write a program to count vowels and consonants in a given string. 111 | **Example**: 112 | Input: `string = "hello world"` 113 | Output: `Vowels: 3, Consonants: 7` 114 | Explanation: "hello world" contains 3 vowels (e, o, o) and 7 consonants (h, l, l, w, r, l, d). 115 | 116 | 13. **Reversing a String** 117 | **Difficulty**: Easy 118 | **Topics**: Basic Programming, String Manipulation 119 | **Description**: Write a program to reverse a given string. 120 | **Example**: 121 | Input: `string = "programming"` 122 | Output: `"gnimmargorp"` 123 | Explanation: The reversed string of "programming" is "gnimmargorp". 124 | 125 | 14. **Finding the Largest and Smallest Numbers in an Array** 126 | **Difficulty**: Easy 127 | **Topics**: Basic Programming, Arrays 128 | **Description**: Write a program to find the largest and smallest numbers in an array. 129 | **Example**: 130 | Input: `array = [4, 7, 1, 8, 5]` 131 | Output: `Largest: 8, Smallest: 1` 132 | Explanation: The largest number in the array is 8 and the smallest is 1. 133 | 134 | 15. **Sorting an Array** 135 | **Difficulty**: Easy 136 | **Topics**: Basic Programming, Sorting Algorithms 137 | **Description**: Write a program to sort an array of numbers in ascending order. 138 | **Example**: 139 | Input: `array = [3, 1, 4, 1, 5, 9]` 140 | Output: `[1, 1, 3, 4, 5, 9]` 141 | Explanation: The array sorted in ascending order is [1, 1, 3, 4, 5, 9]. 142 | 143 | 16. **Finding the Sum of Elements in an Array** 144 | **Difficulty**: Easy 145 | **Topics**: Basic Programming, Arrays 146 | **Description**: Write a program to find the sum of elements in an array. 147 | **Example**: 148 | Input: `array = [1, 2, 3, 4, 5]` 149 | Output: `15` 150 | Explanation: The sum of the elements in the array is 15. 151 | 152 | 17. **Checking for Armstrong Numbers in a Range** 153 | **Difficulty**: Easy 154 | **Topics**: Basic Programming, Number Theory 155 | **Description**: Write a program to find all Armstrong numbers within a given range. 156 | **Example**: 157 | Input: `range = [1, 500]` 158 | Output: `[1, 153, 370, 371, 407]` 159 | Explanation: Armstrong numbers between 1 and 500 are 1, 153, 370, 371, and 407. 160 | 161 | 18. **Generating Multiplication Tables** 162 | **Difficulty**: Easy 163 | **Topics**: Basic Programming, Mathematical Computations 164 | **Description**: Write a program to generate multiplication tables for a given number. 165 | **Example**: 166 | Input: `number = 4` 167 | Output: 168 | ``` 169 | 4 x 1 = 4 170 | 4 x 2 = 8 171 | 4 x 3 = 12 172 | 4 x 4 = 16 173 | 4 x 5 = 20 174 | ``` 175 | Explanation: The multiplication table for 4 up to 5 is generated. 176 | 177 | 19. **Finding Prime Numbers in a Range** 178 | **Difficulty**: Easy 179 | **Topics**: Basic Programming, Number Theory 180 | **Description**: Write a program to find all prime numbers within a given range. 181 | **Example**: 182 | Input: `range = [10, 30]` 183 | Output: `[11, 13, 17, 19, 23, 29]` 184 | Explanation: Prime numbers between 10 and 30 are 11, 13, 17, 19, 23, and 29. 185 | 186 | 20. **Checking for Perfect Numbers** 187 | **Difficulty**: Easy 188 | **Topics**: Basic Programming, Number Theory 189 | **Description**: Write a program to determine if a number is a perfect number. 190 | **Example**: 191 | Input: `number = 28` 192 | Output: `Perfect Number` 193 | Explanation: 28 is a perfect number because its divisors (1, 2, 4, 7, 14) sum up to 28. 194 | 195 | 21. **Calculating the Sum of Even Numbers in a Range** 196 | **Difficulty**: Easy 197 | **Topics**: Basic Programming, Mathematical Computations 198 | **Description**: Write a program to find the sum of all even numbers within a given range. 199 | **Example**: 200 | Input: `range = [1, 10]` 201 | Output: `30` 202 | Explanation: The sum of even numbers between 1 and 10 is 2 + 4 + 6 + 8 + 10 = 30. 203 | 204 | 22. **Calculating the Sum of Odd Numbers in a Range** 205 | **Difficulty**: Easy 206 | **Topics**: Basic Programming, Mathematical Computations 207 | **Description**: Write a program to find the sum of all odd numbers within a given range. 208 | **Example**: 209 | Input: `range = [1, 10]` 210 | Output: `25` 211 | Explanation: The sum of odd numbers between 1 and 10 is 1 + 3 + 5 + 7 + 9 = 25. 212 | 213 | 23. **Finding the Fibonacci Number at a Specific Position** 214 | **Difficulty**: Easy 215 | **Topics**: Basic Programming, Sequences 216 | **Description**: Write a program to find the Fibonacci number at a specific position. 217 | **Example**: 218 | Input: `position = 5` 219 | Output: `5` 220 | Explanation: The Fibonacci number at position 5 is 5 (sequence: 0, 1, 1, 2, 3, 5). 221 | 222 | 24. **Printing Prime Numbers Less Than a Given Number** 223 | **Difficulty**: Easy 224 | **Topics**: Basic Programming, Number Theory 225 | **Description**: Write a program to print all prime numbers less than a given number. 226 | **Example**: 227 | Input: `number = 20` 228 | Output: `2, 3, 5, 7, 11, 13, 17, 19` 229 | Explanation: The prime numbers less than 20 are 2, 3, 5, 7, 11, 13, 17, and 19. 230 | 231 | 25. **Finding the Number of Digits in a Number** 232 | **Difficulty**: Easy 233 | **Topics**: Basic Programming, Mathematical Computations 234 | **Description**: Write a program to count the number of digits in a given number. 235 | **Example**: 236 | Input: `number = 12345` 237 | Output: `5` 238 | Explanation: The number 12345 has 5 digits. 239 | 240 | 26. **Checking if a Number is a Narcissistic Number** 241 | **Difficulty**: Easy 242 | **Topics**: Basic Programming, Number Theory 243 | **Description**: Write a program to check if a number is a narcissistic number (where the sum of its digits raised to the power of the number of digits equals the number itself). 244 | **Example**: 245 | Input: `number = 153` 246 | Output: `Narcissistic Number` 247 | Explanation: 153 is a narcissistic number because 1^3 + 5^3 + 3^3 = 153. 248 | 249 | 27. **Generating a Pattern of Numbers** 250 | **Difficulty**: Easy 251 | **Topics**: Basic Programming, Patterns 252 | **Description**: Write a program to generate number patterns (e.g., sequential numbers in a matrix). 253 | **Example**: 254 | Input: `rows = 3` 255 | Output: 256 | ``` 257 | 1 258 | 2 3 259 | 4 5 6 260 | ``` 261 | Explanation: A number pattern with 3 rows is generated. 262 | 263 | 28. **Finding the Sum of the Digits of the Factorial of a Number** 264 | **Difficulty**: Easy 265 | **Topics**: Basic Programming, Mathematical Computations 266 | **Description**: Write a program to find the sum of the digits of the factorial of a given number. 267 | **Example**: 268 | Input: `number = 4` 269 | Output: `9` 270 | Explanation: The factorial of 4 is 24, and the sum of the digits (2 + 4) is 6. 271 | 272 | 29. **Finding the Largest Palindrome in a String** 273 | **Difficulty**: Easy 274 | **Topics**: Basic Programming, String Manipulation 275 | **Description**: Write a program to find the largest palindrome in a given string. 276 | **Example**: 277 | Input: `string = "babad"` 278 | Output: `"bab"` or `"aba"` 279 | Explanation: Both "bab" and "aba" are valid palindromes in the string. 280 | 281 | 30. **Finding Missing Numbers in a Sequence** 282 | **Difficulty**: Easy 283 | **Topics**: Basic Programming, Arrays 284 | **Description**: Write a program to find missing numbers in a sequence from 1 to n. 285 | **Example**: 286 | Input: `sequence = [1, 2, 4, 5]` 287 | Output: `[3]` 288 | Explanation: The missing number in the sequence from 1 to 5 is 3. 289 | 290 | 31. **Generating a Pascal’s Triangle** 291 | **Difficulty**: Medium 292 | **Topics**: Arrays, Mathematical Computations 293 | **Description**: Write a program to generate Pascal's Triangle up to a given number of rows. 294 | **Example**: 295 | Input: `rows = 4` 296 | Output: 297 | ``` 298 | 1 299 | 1 1 300 | 1 2 1 301 | 1 3 3 1 302 | ``` 303 | Explanation: Pascal's Triangle with 4 rows is generated. 304 | 305 | 32. **Finding the Median of an Array** 306 | **Difficulty**: Medium 307 | **Topics**: Arrays, Sorting 308 | **Description**: Write a program to find the median of an array of numbers. 309 | **Example**: 310 | Input: `array = [3, 1, 2, 4, 5]` 311 | Output: `3` 312 | Explanation: The median of the sorted array [1, 2, 3, 4, 5] is 3. 313 | 314 | 33. **Calculating the Power of a Number** 315 | **Difficulty**: Easy 316 | **Topics**: Basic Programming, Mathematical Computations 317 | **Description**: Write a program to calculate the power of a number. 318 | **Example**: 319 | Input: `base = 2`, `exponent = 3` 320 | Output: `8` 321 | Explanation: 2 raised to the power of 3 is 8. 322 | 323 | 34. **Checking for an Anagram** 324 | **Difficulty**: Easy 325 | **Topics**: String Manipulation 326 | **Description**: Write a program to check if two strings are anagrams. 327 | **Example**: 328 | Input: `string1 = "listen"`, `string2 = "silent"` 329 | Output: `True` 330 | Explanation: "listen" and "silent" are anagrams of each other. 331 | 332 | 35. **Finding the Sum of Prime Numbers in a Range** 333 | **Difficulty**: Medium 334 | **Topics**: Number Theory, Mathematical Computations 335 | **Description**: Write a program to calculate the sum of all prime numbers within a given range. 336 | **Example**: 337 | Input: `range = [1, 10]` 338 | Output: `17` 339 | Explanation: The sum of prime numbers between 1 and 10 is 2 + 3 + 5 + 7 = 17. 340 | 341 | 36. **Finding the N-th Triangular Number** 342 | **Difficulty**: Easy 343 | **Topics**: Basic Programming, Mathematical Computations 344 | **Description**: Write a program to find the N-th triangular number. 345 | **Example**: 346 | Input: `N = 4` 347 | Output: `10` 348 | Explanation: The 4th triangular number is 10 (sum of the first 4 natural numbers). 349 | 350 | 37. **Checking for Perfect Squares** 351 | **Difficulty**: Easy 352 | **Topics**: Mathematical Computations 353 | **Description**: Write a program to determine if a number is a perfect square. 354 | **Example**: 355 | Input: `number = 16` 356 | Output: `True` 357 | Explanation: 16 is a perfect square (4^2 = 16). 358 | 359 | 38. **Finding the Sum of Squares of Digits** 360 | **Difficulty**: Easy 361 | **Topics**: Basic Programming, Mathematical Computations 362 | **Description**: Write a program to find the sum of the squares of the digits of a number. 363 | **Example**: 364 | Input: `number = 123` 365 | Output: `14` 366 | Explanation: The sum of the squares of digits is 1^2 + 2^2 + 3^2 = 14. 367 | 368 | 39. **Generating a Square Matrix of a Given Size** 369 | **Difficulty**: Medium 370 | **Topics**: Arrays, Matrix Operations 371 | **Description**: Write a program to generate a square matrix of a given size and fill it with sequential numbers. 372 | **Example**: 373 | Input: `size = 3` 374 | Output: 375 | ``` 376 | 1 2 3 377 | 4 5 6 378 | 7 8 9 379 | ``` 380 | Explanation: A 3x3 matrix is generated with sequential numbers. 381 | 382 | 40. **Calculating the Sum of Digits of a Number Until Single Digit** 383 | **Difficulty**: Medium 384 | **Topics**: Mathematical Computations 385 | **Description**: Write a program to keep summing the digits of a number until a single digit is obtained. 386 | **Example**: 387 | Input: `number = 9875` 388 | Output: `2` 389 | Explanation: The sum of digits is 9 + 8 + 7 + 5 = 29, and then 2 + 9 = 11, and finally 1 + 1 = 2. 390 | 391 | 41. **Finding the Count of Specific Digits in a Number** 392 | **Difficulty**: Easy 393 | **Topics**: Basic Programming, String Manipulation 394 | **Description**: Write a program to count the occurrences of a specific digit in a number. 395 | **Example**: 396 | Input: `number = 122333`, `digit = 3` 397 | Output: `3` 398 | Explanation: The digit 3 occurs 3 times in the number 122333. 399 | 400 | 42. **Generating a Fibonacci Sequence Using Recursion** 401 | **Difficulty**: Medium 402 | **Topics**: Recursion, Sequences 403 | **Description**: Write a recursive program to generate the Fibonacci sequence up to a given number. 404 | **Example**: 405 | Input: `number = 5` 406 | Output: `0, 1, 1, 2, 3` 407 | Explanation: The Fibonacci sequence up to 5 is generated. 408 | 409 | 43. **Finding All Divisors of a Number** 410 | **Difficulty**: Easy 411 | **Topics**: Basic Programming, Mathematical Computations 412 | **Description**: Write a program to find all divisors of a given number. 413 | **Example**: 414 | Input: `number = 12` 415 | Output: `1, 2, 3, 4, 6, 12` 416 | Explanation: The divisors of 12 are 1, 2, 3, 4, 6, and 12. 417 | 418 | 44. **Finding the Average of Numbers in an Array** 419 | **Difficulty**: Easy 420 | **Topics**: Arrays, Mathematical Computations 421 | **Description**: Write a program to calculate the average of numbers in an array. 422 | **Example**: 423 | Input: `array = [1, 2, 3, 4, 5]` 424 | Output: `3` 425 | Explanation: The average of the numbers is (1 + 2 + 3 + 4 + 5) / 5 = 3. 426 | 427 | 45. **Finding the Mode of Numbers in an Array** 428 | **Difficulty**: Medium 429 | **Topics**: Arrays, Statistical Analysis 430 | **Description**: Write a program to find the mode (most frequent number) in an array. 431 | **Example**: 432 | Input: `array = [1, 2, 2, 3, 4, 4, 4]` 433 | Output: `4` 434 | Explanation: The most frequent number in the array is 4. 435 | 436 | 46. **Determining the Length of a String Without Using Built-In Functions** 437 | **Difficulty**: Medium 438 | **Topics**: String Manipulation 439 | **Description**: Write a program to determine the length of a string without using built-in functions. 440 | **Example**: 441 | Input: `string = "hello"` 442 | Output: `5` 443 | Explanation: The length of the string "hello" is determined without using built-in functions. 444 | 445 | 47. **Generating a Number Pyramid** 446 | **Difficulty**: Medium 447 | **Topics**: Patterns, Basic Programming 448 | **Description**: Write a program to generate a pyramid of numbers (e.g., 1, 12, 123, etc.). 449 | **Example**: 450 | Input: `rows = 4` 451 | Output: 452 | ``` 453 | 1 454 | 12 455 | 123 456 | 1234 457 | ``` 458 | Explanation: A number pyramid with 4 rows is generated. 459 | 460 | 48. **Finding the Sum of Prime Factors of a Number** 461 | **Difficulty**: Medium 462 | **Topics**: Number Theory, Mathematical Computations 463 | **Description**: Write a program to find the sum of the prime factors of a given number. 464 | **Example**: 465 | Input: `number = 12` 466 | Output: `5` 467 | Explanation: The prime factors of 12 are 2 and 3, and their sum is 2 + 3 = 5. 468 | 469 | 49. **Finding the Second Largest Number in an Array** 470 | **Difficulty**: Medium 471 | **Topics**: Arrays, Sorting 472 | **Description**: Write a program to find the second largest number in an array. 473 | **Example**: 474 | Input: `array = [10, 20, 4, 45, 99]` 475 | Output: `45` 476 | Explanation: The second largest number in the array is 45. 477 | 478 | 50. **Finding the Longest Substring Without Repeating Characters** 479 | **Difficulty**: Medium 480 | **Topics**: String Manipulation, Sliding Window 481 | **Description**: Write a program to find the longest substring without repeating characters in a given string. 482 | **Example**: 483 | Input: `string = "abcabcbb"` 484 | Output: `"abc"` 485 | Explanation: The longest substring without repeating characters is "abc". 486 | --------------------------------------------------------------------------------