Skip to content

Instantly share code, notes, and snippets.

View jatinsharrma's full-sized avatar

Jatin Sharma jatinsharrma

  • India
View GitHub Profile
// A C program to count number of ways to reach n't stair when
// a person can climb 1 or 2 stairs at a time.
//if code is wrong or i misssed a case please let me know. If code can be optmised or logic can be reformed please let me know.
#include<stdio.h>
int one = 0;
int two = 0;
int count = 0;
@jatinsharrma
jatinsharrma / NextDate.py
Created May 11, 2019 20:16
Write a program to generate and display the next date of a given date.
def next_date(day,month,year):
flag = False
day = day + 1
if year%4 == 0:
if year % 100:
if year%400 == 0:
@jatinsharrma
jatinsharrma / coins.py
Last active January 6, 2022 09:36
Coins problem: You have coins of 5 and 1 only. You have to find how much you need to make the given number. If you can't output -1
# You have x no. of 5 rupee coins and y no. of 1 rupee coins. You want to purchase an item for amount z.
#The shopkeeper wants you to provide exact change. You want to pay using minimum number of coins.
#How many 5 rupee coins and 1 rupee coins will you use? If exact change is not possible then display -1.
def make_amount(rupees_to_make,no_of_five,no_of_one):
five_needed=0
one_needed=0
five = int(rupees_to_make/5)
one_needed = rupees_to_make%5
@jatinsharrma
jatinsharrma / ProductOnRules.py
Last active May 16, 2023 09:16
rite a python program to find and display the product of three positive integer values based on rules
#Write a python program to find and display the product of three positive integer values based on the rule mentioned below:
#It should display the product of the three values except when one of the integer value is 7. In that case, 7 should not be included in the product and the values to its left also should not be included.
#If there is only one value to be considered, display that value itself. If no values can be included in the product, display -1.
def find_product(num1,num2,num3):
product=0
if (num1 != 7 and num2 != 7 and num3 != 7):
product = num1 * num2 * num3
elif (num1 == 7):
product = num2 * num3
@jatinsharrma
jatinsharrma / Busfair.py
Last active August 15, 2021 08:01
The road transport corporation (RTC) of a city wants to know whether a particular bus-route is running on profit or loss.
# The road transport corporation (RTC) of a city wants to know whether a particular bus-route is running on profit or loss.
# Assume that the following information are given:
# Price per litre of fuel = 70
# Mileage of the bus in km/litre of fuel = 10
# Price(Rs) per ticket = 80
# The bus runs on multiple routes having different distance in kms and number of passengers.
# Write a function to calculate and return the profit earned (Rs) in each route. Return -1 in case of loss.
@jatinsharrma
jatinsharrma / RunLengthEncoding.py
Created May 14, 2019 20:52
Python function which performs the run length encoding for a given String and returns the run length encoded String.
def encode(message):
count = 0
chatacter = ''
previous_char = message[0]
result = ''
length = len(message)
i = 0
while (i != length ):
chatacter = message[i]
@jatinsharrma
jatinsharrma / CheckPalindrome.py
Created May 14, 2019 21:12
Python function to check whether the given string is a palindrome or not.
def check_palindrome(word):
length = len(word)
for i in range(int(length/2)):
if word[i] != word [length - i - 1]:
return 0
return 1
status=check_palindrome("malayalam")
if(status):
@jatinsharrma
jatinsharrma / CareHospital.py
Created May 17, 2019 10:12
Care hospital wants to know the medical speciality visited by the maximum number of patients.
# Care hospital wants to know the medical speciality visited by the maximum number of patients. Assume that the patient id of the patient along with the medical speciality visited by the patient is stored in a list. The details of the medical specialities are stored in a dictionary as follows:
# {
# "P":"Pediatrics",
# "O":"Orthopedics",
# "E":"ENT
# }
# Write a function to find the medical speciality visited by the maximum number of patients and return the name of the speciality.
# Also write the pytest test cases to test the program.
@jatinsharrma
jatinsharrma / CommonCharacter.py
Last active February 1, 2022 18:31
Write a python program to display all the common characters between two strings. Return -1 if there are no matching characters.
# Write a python program to display all the common characters between two strings. Return -1 if there are no matching characters.
def find_common_characters(msg1,msg2):
result = []
if len(msg1) > len(msg2):
result = my_func(msg1,msg2)
else:
result = my_func(msg2,msg1)
@jatinsharrma
jatinsharrma / generate_ticket.py
Created July 13, 2019 16:01
Write a python program to generate the ticket numbers for specified number of passengers traveling in a flight.
# Write a python program to generate the ticket numbers for specified number of passengers traveling in a flight as per the details mentioned below:
# The ticket number should be generated as airline:src:dest:number
# where :
# 1. Consider AI as the value for airline
# 2. src and dest should be the first three characters of the source and destination cities.
# 3. number should be auto-generated starting from 101
# The program should return the list of ticket numbers of last five passengers.
# Note: If passenger count is less than 5, return the list of all generated ticket numbers.
def generate_ticket(airline,source,destination,no_of_passengers):