Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

DS SEARCHING CODING TEST


Program 1:

Problem Statement :
This is a simple challenge to get things started. Given a sorted array (arr) and a
number (V), can you print the index location of V in the array? 
Input Format 
The rst line contains an integer, V , a value to search for. The next line contains an integer, n , the size of arr. The last line contains n space-separated integers, each a value of arri where 0<=i<n] .
 Output Format 
Output the index of V in the array.

Program In Python:

c=int(input())
d=int(input())
a=list(map(int,input().split()))
print(a.index(c))


Program 2:

Problem Statement Skyline Real Estate Developers is planning to demolish a number of old, unoccupied buildings and construct a shopping mall in their place. Your task is to nd the largest solid area in which the mall can be constructed. There are a number of buildings in a certain twodimensional landscape. Each building has a height, given by hi where i belongs to 1,n . If you join k adjacent buildings, they will form a solid rectangle of area . k*min(hi,hi+1,…...hi+k-1). For example, the heights array h=3,2,3. A rectangle of height h=2 and length k=3 can be constructed within the boundaries. The area formed is h.k=2.3=6 . Input Format The rst line contains n , the number of buildings. The second line contains n space-separated integers, each representing the height of a building. Output Format Print a long integer representing the maximum area of rectangle formed.

program in python:

def solve(H) :
    s,i,m = [],0,0
    while i < len(H) :
        if not s or H[i] > H[s[-1]] :
            s.append(i)
            i += 1
        else :
            t = s.pop()
            a = H[t] * ((i - s[-1] -1)  if s else i)
            if a > m :
                m = a      
    while s :
        t = s.pop()
        a = H[t] * ((i - s[-1] -1)  if s else i)
        if a > m :
            m = a
    return m           
N = int(input())
H = list(int(_) for _ in input().split())
print(solve(H))


Post a Comment

Previous Post Next Post