https://github.com/imdarshangk/hackerrank
This repository showcases my solutions to various coding challenges on HackerRank. It covers a range of topics, including algorithms, data structures, and problem-solving skills. The solutions are organized by categories for easy navigation.
https://github.com/imdarshangk/hackerrank
arithmetic-operators find-a-string finding-the-percentage hackerrank hackerrank-solutions if-else leap-year loops
Last synced: about 2 months ago
JSON representation
This repository showcases my solutions to various coding challenges on HackerRank. It covers a range of topics, including algorithms, data structures, and problem-solving skills. The solutions are organized by categories for easy navigation.
- Host: GitHub
- URL: https://github.com/imdarshangk/hackerrank
- Owner: imDarshanGK
- Created: 2023-03-14T18:00:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-19T14:42:55.000Z (2 months ago)
- Last Synced: 2025-02-19T15:43:20.617Z (2 months ago)
- Topics: arithmetic-operators, find-a-string, finding-the-percentage, hackerrank, hackerrank-solutions, if-else, leap-year, loops
- Language: Python
- Homepage: https://www.hackerrank.com/profile/imDarshanGk
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HackerRank Solutions 💻
## Overview
This repository contains my solutions to various coding challenges and problems solved on **HackerRank**. It showcases my problem-solving skills in different domains such as algorithms, data structures, mathematics, and more.## Features
- Solutions to multiple HackerRank problems.
- Organized by categories (e.g., Algorithms, Data Structures).
- Code comments explaining key concepts and steps.# Find a string
```
Find a string.In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left.
NOTE: String letters are case-sensitive.
Input Format
The first line of input contains the original string. The next line contains the substring.Constraints
1 < len(string) < 200Each character in the string is an ascii character.
Output Format
Output the integer number indicating the total number of occurrences of the substring in the original string.Sample Input
ABCDCDC
CDC
Sample Output
2
Concept
Some string processing examples, such as these, might be useful.
There are a couple of new concepts:
In Python, the length of a string is found by the function len(s), where is the string.To traverse through the length of a string, use a for loop:
for i in range(0, len(s)):
print (s[i])
A range function is used to loop over some length:
range (0, 5)
Here, the range loops over 0 to 4.5 is excluded.
```# Finding the percentage
```
Finding the percentageThe provided code stub will read in a dictionary containing key/value pairs of name:[marks] for a list of students. Print the average of the marks array for the student name provided, showing 2 places after the decimal.
Example
marks key:value pairs are
'alpha': [20,30,40]
'beta': [30,50,70]
query_name='beta'The query_name is 'beta'. beta's average score is (30+50+70)/3 = 50.0 .
Input Format
The first line contains the integer n, the number of students' records. The next n lines contain the names and marks obtained by a student, each value separated by a space. The final line contains query_name, the name of a student to query.Constraints
* 2 < n 10
* 0 < marks[i] < 100
* length of marks arrays = 3Output Format
Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.Sample Input 0
3
Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60
MalikaSample Output 0
56.00
Explanation 0Marks for Malika are {52,56,60} whose average is 52+56+60/3 => 56
Sample Input 1
2
Harsh 25 26.5 28
Anurag 26 28 30
HarshSample Output 1
26.50
```# write a function
```
write a function
TaskGiven a year, determine whether it is a leap year. If it is a leap year, return the Boolean True, otherwise return False.
Note that the code stub provided reads from STDIN and passes arguments to the is_leap function. It is only necessary to complete the is_leap function.Input Format
Read year, the year to test.Constraints
1900 < year < 10^5Output Format
The function must return a Boolean value (True/False). Output is handled by the provided code stub.Sample Input 0
1990Sample Output 0
FalseExplanation 0
1990 is not a multiple of 4 hence it's not a leap year.
```# If Else
```
If Else
TaskGiven an integer, , perform the following conditional actions:
* If n is odd, print Weird
* If n is even and in the inclusive range of 2 to 5, print Not Weird
* If n is even and in the inclusive range of 6 to 20, print Weird
* If n is even and greater than 20, print Not WeirdInput Format
A single line containing a positive integer,n .Constraints
* 1 < n < 100
Output Format
Print Weird if the number is weird. Otherwise, print Not Weird.Sample Input 0
3Sample Output 0
WeirdExplanation 0
n=3
n is odd and odd numbers are weird, so print Weird.Sample Input 1
24Sample Output 1
Not Weird
Explanation 1
n=24
n>20 and nis even, so it is not weird.
```