Posts

String Membership in Python

String Membership You just need to take string and a character as an input from stdin and print 'True' if that character is present in that string otherwise print 'False'. Input Format You will be taking a string and a character as an input from stdin. Constraints 1 Output Format Print 'True' if that character is present in that string otherwise print 'False'. Sample TestCase 1 Input Hello Techgig H Output True Solution: import sys def main(): # Write code here ip1=raw_input() ip2=raw_input() length=len(ip1) for i in range(0,length): if(ip2==ip1[i]): sys.stdout.write("True") break else: sys.stdout.write("False") break main()

String Repetition in Python

String Repetition You just need to take a string and a integer as an input from stdin and repeat the string up to the count given as in integer. Input Format You will be taking a string and an integer as an input from stdin. Constraints 1 1 Output Format You need to print the string to the stdout. Sample TestCase 1 Input Hello 2 Output HelloHello Solution import sys def main(): # Write code here ip1=raw_input() val=input() for i in range(0,val): sys.stdout.write(ip1) main()

String Concatenation in Python

String Concatenation You just need to take two strings as input from stdin and concatenate them and print the concatenated string to the stdout. Input Format You will be taking two strings as an input from stdin one on each line respectively. Constraints 1 Output Format You need to print the concatenated string to the stdout. Sample TestCase 1 Input Hello Techgig Output HelloTechgig Solution import sys def main(): # Write code here ip1=raw_input() ip2=raw_input() sys.stdout.write(str(ip1).strip(" ")+str(ip2).strip(" ")) main()

Print Exact Slice Of String in Python

Print Exact Slice Of String You need to take string input and two other numbers which will be the start and end point of the slice and you need to print that slice of string to the stdout. Input Format You will be taking a string as an input from stdin and two integers one on each line. Constraints 1 Output Format You need to print the slice of the string to the stdout. Sample TestCase 1 Input Hello Techgig 1 4 Output ello import sys def main(): # Write code here word=raw_input() one=input() two=input() obj=slice(one,two+1) sys.stdout.write(str(word[obj])) main()

Power of a Number in Python

Python.math module provides access to the mathematical functions defined by the C standard. One of the widely used function is math.pow(x, y) which Returns x raised to the power y. Now, you are given three integers x, y and M. You have to print ( x ^ y ) Mod M. Input format First line will contain three integers x, y, and M. Constraints 1 1 2 Output Format Print an Integer denoting answer of the calculation (x ^ y ) Mod M. Sample TestCase 1 Input 10 2 3 output 1 Explanation 10^2 = 100 100%3=1 Solution : import sys import math def main(): # Write code here ip=raw_input() ip=map(int,ip.split(' ')) x=int(ip[0]) y=int(ip[1]) m=int(ip[2]) o1=math.pow(x,y) o2=o1%m sys.stdout.write(str(int(o2))) main()

Find Angle in Python

Image
Given a right angled triangle ABC, right angled at B. Find angle ABD, where D is the mid-point of the hypotenuse(side AC). You will be given two integers denoting sides AB and BC respectively. Round off your answer to the nearest Integer. Input Format First line will contain an Integer denoting side AB. Second line will contain an Integer denoting side BC. Constraints 1 <= side AB <= 200 1 <= side BC <= 200 output Output Angle ABD, rounded off to nearest integer. Sample TestCase 1 Input case 6 6 output 45 Solution: import sys import math def main(): # Write code here adjacent=input() opposite=input() #since tan=opposite/adjacent tangent=opposite/adjacent sys.stdout.write(str(int(math.degrees(math.atan(tangent))))) main()

Fibonacci series in Python

''' Read input from STDIN. Print your output to STDOUT ''' #Use input() to read input from STDIN and use print to write your output to STDOUT import sys def main(): # Write code here val=input() x=0 y=1 z=x+y sys.stdout.write(str(x)+" "+str(y)) for i in range(val-2): z=x+y x=y y=z sys.stdout.write(" "+str(z)) main()

Maths and Java

Question: A sum of 3000 INR is to be given  in the form of 63 prizes. If the prize money  is either 100 INR or 25 INR. Find the number of prizes of each type. Maths:  Let the count of prizes in sum of rupees 100 each be X              Then the value of prize be 100X           Let the count of prizes in sum of rupees 25 each be Y             Then the value of prize be 25Y         Total number of prizes is X+Y=63     ----------->1                     X=63-Y            Now the Total prize value  is 3000.          Then 100X+25Y=3000                --------->2            100(63-Y)+25Y=3000                  ...

Sort 5 multiples in ascending order using java

For this challenge, you will be given an array and you are asked to find multiples of 5 in the given array, sort and put them first in the array. Rest all the elements will preserve their orders.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  print the required array to the STDOUT.  Sample Test Case:   Sample Input: - 6 9 14 15 10 8 5 Sample Output  -  5 10 15 9 14 8

Count triplet in java

Task  -  You will be given an array and a number and you need to find the number of triplet in the array whose sum is equal to given number in the input.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them. Next line should have a integer value.  Output Format  -  you need to print the number of triplet of integers in the array whose sum is equal to the given integer.  Sample Test Case:   Sample Input: - 4 2 5 7 -1 6  Sample Output  -  1 Explanation:   There is 1 triplet with sum 6 which is (2, 5, -1). So, output is 1.

Third Largest in java.

You will be given 4 numbers one on each line and you are asked to find the second largest number and print them to the STDOUT .  Input Format  -  You will take 4 integers as input from STDIN.  Output Format  -  print your result which will be the integer only to the STDOUT.  Sample Test Case:   Sample Input: - 234 213 666 879  Sample Output  -  234

Add occurrences of thrice in java

In this challenge you need to check for thrice occurrences in array and sum it up. Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  You need to print the sum of the numbers occurring Thrice.  Sample Test Case:   Sample Input: - 12 9 8 7 7 8 6 5 4 7 8 1 2  Sample Output  -  15 Explanation:   elements 8 and 7 occurring Thrice and their sum is 15.

Second to smaller and larger in java

You will be given an array and you need to find the second largest and second smallest numbers and add them.  Note:  the length of the array should not be less than 2.  Input Format  -  you will be taking a number as an input from stdin which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  you need to print the addition of second largest and second smallest elements to the stdout.  Sample Test Case:   Sample Input: - 7 48 77 7 11 49 99 78 Sample Output  -  89

Largest Even in java

Task - For this challenge, you will be given an array and you are asked to find the largest even number and print it to the STDOUT.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  print the largest even number to the STDOUT.  Sample Test Case:   Sample Input: - 6 78 92 44 63 71 97 Sample Output  -  92  Explanation:   In the given array, 78, 92 and 44 are the even numbers and we need to find the largest even number which is 92.

Multiply Negative numbers in java

For this challenge, you will be given an array and you are asked to count how many numbers are negative and multiply them and print the output to the STDOUT.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  print the multiplication to the STDOUT.  Sample Test Case:   Sample Input: - 7 -8 -7 6 0 7 -1 6 Sample Output  -  -56  Explanation:   There are three negative numbers present in the array and their multiplication comes out to be -56.

Check Occurrences in java

You will be given an array and you need to find the whether there is any element occurring thrice. If yes, then print 'True' else print 'False'  Input Format  -  You will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  You need to print the Boolean value.  Sample Test Case:   Sample Input: - 12 9 8 7 7 8 6 5 4 7 8 1 2  Sample Output  -  True  Explanation:   Elements 8 and 7 occurring Thrice and hence printing 'True'.

Second Odd Largest in java

You will be given an array and you need to find the second largest odd number and print it to the STDOUT.  Input Format  -  you will be taking a number as an input from STDIN which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  you need to print the second largest odd number to the STDOUT.  Sample Test Case:   Sample Input: - 7  25 26 7 8 10 11 79  Sample Output  -  25 

Squaring Every Index in java

You will be given an array and you need to square the elements of the array, add them and print them to the stdout.  Input Format  -  you will be taking a number as an input from stdin which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  You need to print the sum of the numbers.  Sample Test Case:   Sample Input: - 12  9 8 7 7 8 6 5 4 6 5 1 2  Sample Output  -  450 

Second Largest Even in java

For this challenge, you will be given an array and you are asked to find the second largest even number and print it to the stdout.  Input Format  -  you will be taking a number as an input from stdin which tells about the length of the array. On another line, array elements should be there with single space between them.  Output Format  -  print the second largest even number to the stdout.  Sample Test Case:   Sample Input: - 6 78 92 44 63 71 97 Sample Output  -  78 

Leaders in Java

  Write a program to print all the LEADERS in the array. An element is leader if it is greater than all the elements to its right side. And the rightmost element is always a leader. For example int the array {16, 17, 4, 3, 5, 2}, leaders are 17, 5 and 2. Sample Test Case:  Sample Input:- 6 16 17 4 3 5 2 Sample Output -  17 5 2