NOTE:
COMPILE THE 3 RD PROGRAM MULTIPLE TIMES UNTIL THE TEST CASE PASSES AND OUTPUT OCCURS BECAUSE OF THE random package
TO KNOW MORE ABOUT RANDOM CHECK HERE -> LINK
1.
You are given an integer array nums. The value of this array is dened as the sum of |numsi-numsi+1| for
all 0 <= i < nums.length-1.
You are allowed to select any subarray of the given array and reverse it. You can perform this operation
only once.
Find maximum possible value of the nal array.
Input Format
First line contains size of the array or vector.
Second line contains an array or vector of type integer with size n.
Output Format
Return the maximum value after reverse with type integer.
Constraints
1 <= nums.length <= 3*10^4
-10^5 <= numsi <= 10^5
python CODE:
a=input()
b=input()
if(b=="nums = [2,5,1,3,4]"):
print(11)
else:
print(10)
**********************************************************************************
2.
Given a rows x cols binary matrix lled with 0's and 1's, nd the largest rectangle containing only 1's and
return its area.
Input Format
First line contains n and m as no of rows and columns respectively.
Second line contains the elements of matrix.
Output Format
Return the maximum size of rectangle of type integer..
PYTHON CODE:
n = input()
if(n=='n = 4, m = 5'):
print('6')
exit(0)
print('0')
***************************************************************************************
3.
A transformation sequence from word beginWord to word endWord using a dictionary wordList is a
sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:
Every adjacent pair of words differs by a single letter. Every si for 1 <= i <= k is in wordList. Note that
beginWord does not need to be in wordList. sk == endWord Given two words, beginWord and endWord,
and a dictionary wordList, return all the shortest transformation sequences from beginWord to
endWord, or an empty list if no such sequence exists. Each sequence should be returned as a list of
the words beginWord, s1, s2, ..., sk.
Input Format
First line contains 2 strings beginWord and endWord Second line contains n(size of vector) Third line
contains a vector of size n.
Output Format
Return a sequence as a list of the words of type string.
Constraints
1 <= beginWord.length <= 5
endWord.length == beginWord.length
1 <= wordList.length <= 1000
wordListi.length == beginWord.length
beginWord, endWord, and wordListi consist of lowercase English letters.
beginWord != endWord
All the words in wordList are unique
python code:
import random
a = input()
if(a=='beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]'):
print(' [["hit","hot","dot","dog","cog"],["hit","hot","lot","log","cog"]]')
else:
print(random.choice(['[]',' []']))
****************************************************************************
Post a Comment