Coding

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

02.

Creating Potygon

Problem Statement Now let's start coding:


02 sa closed plane figure composed of three or more line Language: Python 3.10
Polygon: Apoa i smaler than the sum of its ote s s
segnents in which its longe 1 nint (ánput (0)
You are given an array sze n narned sides. Find the polygon with the 2 val-list (map( int ,input (). split () ))
Largest perimeter that can be farmed from the given sides and print the
3 val. sort (reverseTrue)
perimeter of the sarne 4 perieeters 1
5 for i in range(n) t
Note if vali]<sun(val[i+l: J) :
The Array will r t be empty. perineter=sun(val[i: ])
Each element of the array 0 break
. If a polygon Cannot be formed from the given sides, then print -1 9 print (perimeter)

Input Format:
The input conssts of two lines
. The first line consists dt a single irteger denoting n.
The second line consists of n space-separated integers denoting the
array sides
The input will be read from the STDIN by the candidate

Output Format:
Print the perimeter of the polygon otherwise print -1.
The output will be matched to the candidate's output printed on the
STDOUT
01. Sub-sequence Problem
Problem Statement Now let's start coding :
You are given an array arr of size N, your task is to re-order the
array and find the length of the longest increasing sub-sequence Language: Python 3.10
from that re-ordered array and print the same as the output. 1 naint (input())
2 arr=[]
A sub-sequence of a given sequence is a sequence that can be 3 for _ in range (n):
derived from the given sequence by deleting some or no elements 4 "arr. append (int (input ()))
without changing the order of the remaining elements. 5 arr.sort ()
6 print(l en(set(arr) ))
Input Format:
The input is in the foilowing format:
. The first line contains N, denoting the number of elements
in the array arr

Then, N subsequent lines contain a single integer, denoting


the value of theelernent of the array arr.
The input will be read from the STDIN by the candidate
02. MaxDiff

Problem State ment Now let's start coding :


is to find
.
You are given an integer array arr of length n. Your task Language: Python 3.10 v
and print the maximum index difference j- k in arr such that
1 naint ( input (0)
arr[k] < arrý] where k<j. 2 arr=list (map{ int, input(). split(0))
3 res=e
Note: 4 for k in range (n) :
Array index starts from 0. for j in range(k+1,n) :
If no such index is found print -1. -if arr[k]<arr[il:
7 resamax(res, j-k)

Input Format: 8 print (res)


The input consists of two lines:
The first line contains n.
The second line contains arr.

Input will be read from the STDIN by the candidate

Output Format:
Print the maximum index difference 1-k.
The output will be matched to the candidate's output
printed on the STDOUT
01. String Conversion
1.
Problem Statement Now let's start coding:
string X into
You are given a string X. Your task s to convert the Language: Python 3.10 v
string Y such that Y represents the minimum possible number
the characters of X with 1 x=input ()
that can be formed from X by replacing
(9 the value of the character to be replaced), i.e. you can
3 if x[ej="9" :
replace a character d in X with (9 - d) in Y -if int(x[e])>m5:
5 -y*wstr(9-int(x[e]))
Note: -else:
The string should not start with a zero and the transformed string 7 "y+*str(int(x[e]))
Y must have the same number of characters as X. 8 else:
-y+zstr(int (x [e)))
Input Format: 10 for i in range(1,len(*)):
The input consist of a single line: 11 if int(x[il)>m5 :
The line contains a string X. 12 *y+zstr(9-int(x[i]))
.
-else:
The input will be read from the STDIN by the candidate.
13
14 y+mx[i ]
15 print (y)
Output Format:
Print the string Y such that Y represents the minimum possible
number that can be formed from X.
The output will be matched to the candidate's output
printed on the STDOUT.

Constraints:

You might also like