This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def next_date(day,month,year): | |
flag = False | |
day = day + 1 | |
if year%4 == 0: | |
if year % 100: | |
if year%400 == 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encode(message): | |
count = 0 | |
chatacter = '' | |
previous_char = message[0] | |
result = '' | |
length = len(message) | |
i = 0 | |
while (i != length ): | |
chatacter = message[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |