Skip to content

ammarisme/hacker-rank-python-challenges

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Challenges and Solutions

This documentation provides an overview of various coding challenges and their solutions. Each challenge is explained along with the approach taken to solve it.

Challenges

0. Alphabet Rangoli

  • Challenge: Create a rangoli pattern using the alphabet.
  • Solution: Generate a list of alphabets and form a symmetric pattern by concatenating them with hyphens.

1. Reduce Function

  • Challenge: Use the reduce function to multiply fractions.
  • Solution: Use the reduce function from the functools module to multiply a list of fractions.

2. Leap Year

  • Challenge: Determine if a given year is a leap year.
  • Solution: Check if the year is divisible by 4 and not 100, or divisible by 400.

3. Find the Runner-up Score!

  • Challenge: Find the second highest score in a list of scores.
  • Solution: Sort the unique scores and select the second highest one.

4. Triangle Quest

  • Challenge: Print a specific pattern using numbers.
  • Solution: Use nested loops and mathematical operations to generate the required pattern.

5. Integers Come in All Sizes

  • Challenge: Perform mathematical operations on large integers.
  • Solution: Use Python's built-in pow function to handle large integer calculations.

6. Power - Mod Power

  • Challenge: Compute power and modular power of integers.
  • Solution: Use the pow function with two and three arguments to compute the power and modular power.

7. Itertools Combinations with Replacements

  • Challenge: Generate combinations with replacement using itertools.
  • Solution: Use itertools.combinations_with_replacement to generate and print combinations.

8. Itertools Combinations

  • Challenge: Generate combinations of a given length using itertools.
  • Solution: Use itertools.combinations to generate and print combinations of varying lengths.

9. Symmetric Difference

  • Challenge: Find the symmetric difference between two sets.
  • Solution: Use set operations to compute the symmetric difference and print the result.

10. No Idea!

  • Challenge: Calculate the happiness score based on elements in sets A and B.
  • Solution: Use set operations to count the number of elements in set A and subtract those in set B.

11. Introduction to Sets

  • Challenge: Calculate the average of unique elements in an array.
  • Solution: Convert the array to a set and compute the average.

12. Itertools Permutations

  • Challenge: Generate permutations of a given length using itertools.
  • Solution: Use itertools.permutations to generate and print permutations.

13. Collections Counter

  • Challenge: Use the Counter class to solve a problem involving item counts.
  • Solution: Use collections.Counter to count and manage item quantities.

14. Itertools Product

  • Challenge: Generate the Cartesian product of input iterables.
  • Solution: Use itertools.product to generate and print the Cartesian product.

15. Capitalize

  • Challenge: Capitalize the first letter of each word in a string.
  • Solution: Split the string by spaces, capitalize each word, and join them back.

16. String Formatting

  • Challenge: Format a given integer into different bases.
  • Solution: Use string formatting to convert and align integers in various bases.

17. Designer Doormat

  • Challenge: Create a designer doormat pattern.
  • Solution: Use loops and string operations to generate the required pattern.

18. Text Wrap

  • Challenge: Wrap a string into a paragraph of given width.
  • Solution: Use string slicing and the textwrap module to wrap the text.

19. String Validation

  • Challenge: Check various properties of a string (alphanumeric, alphabetical, digits, etc.).
  • Solution: Use string methods like isalnum, isalpha, isdigit, etc., to validate the string.

20. Find a String

  • Challenge: Count occurrences of a substring in a string.
  • Solution: Use loops and slicing to find and count the occurrences of the substring.

21. Mutations

  • Challenge: Modify a character at a given index in a string.
  • Solution: Convert the string to a list, modify the character, and join it back to a string.

22. What's Your Name?

  • Challenge: Print a personalized greeting message.
  • Solution: Concatenate strings with formatted placeholders.

23. String Split and Join

  • Challenge: Split a string by spaces and join with hyphens.
  • Solution: Use split and join string methods.

24. sWAP cASE

  • Challenge: Swap the case of each character in a string.
  • Solution: Use string methods to convert uppercase to lowercase and vice versa.

25. Tuples

  • Challenge: Compute the hash of a tuple.
  • Solution: Convert a list of integers to a tuple and use the hash function.

26. List

  • Challenge: Perform various list operations based on user input.
  • Solution: Use list methods like insert, append, remove, etc., to manipulate the list.

27. Finding the Percentage

  • Challenge: Calculate the average percentage of marks for a student.
  • Solution: Compute the average of a list of marks and format the result.

28. Nested Lists

  • Challenge: Find students with the second lowest grade.
  • Solution: Sort the list of grades and extract the names with the second lowest grade.

29. Find the Runner-up Score!

  • Challenge: Find the second highest score in a list.
  • Solution: Sort the unique scores and select the second highest one.

30. List Comprehension

  • Challenge: Generate a list based on certain conditions.
  • Solution: Use list comprehensions to generate the list based on given conditions.

31. Print Function

  • Challenge: Print numbers from 1 to n without spaces.
  • Solution: Use a loop to concatenate and print the numbers.

32. Write a Function

  • Challenge: Determine if a given year is a leap year.
  • Solution: Check if the year is divisible by 4 and not 100, or divisible by 400.

33. Loops

  • Challenge: Print squares of numbers from 0 to n-1.
  • Solution: Use a loop to print the squares of the numbers.

34. Python Division

  • Challenge: Perform integer and float division.
  • Solution: Use the division operator to compute and print the results.

35. Arithmetic Operations

  • Challenge: Perform basic arithmetic operations.
  • Solution: Use addition, subtraction, and multiplication operators.

36. Python If-Else

  • Challenge: Print different outputs based on conditions.
  • Solution: Use if-else statements to handle various conditions.

37. Say Hello with Python

  • Challenge: Print "Hello, World!".
  • Solution: Use the print function to display the message.

About

Python challenges from hackerrank.com

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors