Knowee
Questions
Features
Study Tools

Single File Programming QuestionProblem StatementYou are given a positive integer X. Write a simple program to find the second largest digit in the given number X.Example 1:Input: X = 9765Output: 7Explanation: The second largest digit in 9765 is 7.Example 2:Input: X = 11Output: -1Explanation: If there is no second-largest digit found in the given number, print -1.Note: This question was asked in the Wipro coding test.Input format :The input consists of a positive integer X.Output format :The output prints an integer, representing the second largest digit in the given number X.If there is no second largest digit, the output prints "-1".Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:500 ≤ X ≤ 106Sample test cases :Input 1 :99856Output 1 :8Input 2 :555Output 2 :-1Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Question

Single File Programming QuestionProblem StatementYou are given a positive integer X. Write a simple program to find the second largest digit in the given number X.Example 1:Input: X = 9765Output: 7Explanation: The second largest digit in 9765 is 7.Example 2:Input: X = 11Output: -1Explanation: If there is no second-largest digit found in the given number, print -1.Note: This question was asked in the Wipro coding test.Input format :The input consists of a positive integer X.Output format :The output prints an integer, representing the second largest digit in the given number X.If there is no second largest digit, the output prints "-1".Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:500 ≤ X ≤ 106Sample test cases :Input 1 :99856Output 1 :8Input 2 :555Output 2 :-1Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python solution for the problem:

def second_largest_digit(n):
    # Convert the number to a list of its digits
    digits = [int(d) for d in str(n)]
    # If there is only one unique digit, return -1
    if len(set(digits)) < 2:
        return -1
    # Otherwise, return the second largest digit
    else:
        return sorted(list(set(digits)))[-2]

# Test the function with the provided examples
print(second_largest_digit(9765))  # Output: 7
print(second_largest_digit(11))  # Output: -1
print(second_largest_digit(99856))  # Output: 8
print(second_largest_digit(555))  # Output: -1

This program works by first converting the input number to a list of its digits. It then checks if there is more than one unique digit. If there is only one unique digit, it returns -1. Otherwise, it sorts the list of unique digits and returns the second largest one.

This problem has been solved

Similar Questions

You are given a positive integer X. Write a simple program to find the second largest digit in the given number X.

Single File Programming QuestionProblem StatementOlivia is a curious mind exploring the world of digits. Create a simple program to assist Olivia in understanding the addition of the last two digits of a given number. Prompt Olivia to input an integer n, calculate, and display the sum of the last two digits.Input format :The input consists of an integer n.Output format :The output displays the sum of the last two digits of the input integer.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:10 ≤ n ≤ 105Sample test cases :Input 1 :10Output 1 :1Input 2 :231Output 2 :4Input 3 :7896Output 3 :15Input 4 :100000Output 4 :0Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Single File Programming QuestionProblem Statement Emma needs your help in deciding which of the two numbers is smaller. Create a program that takes two integers as input, identifies the minimum using a relational operator, and displays it.Input format :The input consists of two space-separated integers.Output format :The output prints the smallest of the given input numbers.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:-107 ≤ input integers ≤ 107Sample test cases :Input 1 :89 98Output 1 :89Input 2 :745 -968Output 2 :-968Input 3 :-2536 -2578Output 3 :-2578Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Single File Programming QuestionProblem StatementSathish wants to create a program to check whether its digits are in descending order. The program should output "Yes" if the digits are in descending order and "No" otherwise. He wants to get an integer input that has unique digits in it and determine whether the number meets this condition. Write a program to assist Sathish in completing this task using the goto statement.For example, In the number 4321, all the digits are in descending order.Input format :The input consists of an integer N, that represents the number to be checked.Output format :If the digits of N are in descending order, the output prints "Yes".Else, the output prints "No".Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ N < 105Sample test cases :Input 1 :2589Output 1 :NoInput 2 :4321Output 2 :YesInput 3 :93578Output 3 :No

Single File Programming QuestionProblem StatementPaul is working on a program to manipulate 4-digit numbers. Write a program for him toRemove the last digit.Print the resulting number.Add 1 to the resulting number.Print the result.Note: This question helps in implementing logic for company-specific questions.Input format :The input consists of an integer N, representing the 4-digit number.Output format :The output prints the modified numbers, separated by space.Refer to the sample output for formatting specifications.Code constraints :1000 ≤ N ≤ 9999Sample test cases :Input 1 :1000Output 1 :100 101Input 2 :5896Output 2 :589 590Input 3 :9999Output 3 :999 1000

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.