TCS Coding Question 2022 Day 1 Slot 2

Coding Question 2 for 2022 (September slot)

In this article, we will discuss about the TCS Coding Question which is asked in the TCS placement test. This type of Coding Questions will help you to crack your upcoming TCS exam as well as during your inteview process.

TCS Coding Question 2 Day 1 slot 2

TCS Coding Question Day 1 Slot 2 – Question 2

Given an integer array Arr of size N the task is to find the count of elements whose value is greater than all of its prior elements.

Note : 1st element of the array should be considered in the count of the result.

For example,

Arr[]={7,4,8,2,9}

As 7 is the first element, it will consider in the result.

8 and 9 are also the elements that are greater than all of its previous elements.

 

Since total of  3 elements is present in the array that meets the condition.

Hence the output = 3.

 

 Example 1:

Input 

5 -> Value of N, represents size of Arr

7-> Value of Arr[0]

4 -> Value of Arr[1]

8-> Value of Arr[2]

2-> Value of Arr[3]

9-> Value of Arr[4]

 

Output :

3

 

Example 2:

5   -> Value of N, represents size of Arr

3  -> Value of Arr[0]

4 -> Value of Arr[1]

5 -> Value of Arr[2]

8 -> Value of Arr[3]

9 -> Value of Arr[4]

 

Output : 

5

 

Constraints

  • 1<=N<=20
  • 1<=Arr[i]<=10000

14 comments on “TCS Coding Question 2022 Day 1 Slot 2”


  • Aditya

    // taking the smallest value possible in integer data type
    int max=Integer.MIN_VALUE;
    //count to take a count of number of elements greater then previous one
    int count=0;
    // for loop starting from 0 and going till the size if an array
    for(int i=0;imax, increase the count by 1 and put the element in max
    if(arr[i]>max)
    {
    max=arr[i];
    count++;
    }
    }
    System.out.println(count);

    // let example 7,4,8,6,9
    max=-2147483648
    at i=0;
    7 is greater then -2147483648, count=1, and max=7
    at i=1;
    4 is not greater then 7,do nothing
    at i=2
    8 is greater then 7, count=2, and max=8.
    at i=3
    6 is not greater then 8, do nothing
    at i=4
    9 is greater then 8,count=3,max=9

    now we don’t have any element in our array, just print the answer

    😉


  • ANKUSH

    #include
    using namespace std;
    int main(){

    int arr[] = {5,7,8,2,9};
    int n = 5;
    int count = 1;
    for(int i = 1;i arr[i-1])
    {
    count++;
    }
    }
    cout << count;
    return 0;
    }


  • Chethan

    lst = list(map(int, input().split()))
    Count = [i for I in lst if i >= lst[0]]
    print(len(count) + 1)


  • Venkatesh

    python code:
    n = int(input(“Enter the size of array: “))
    li = []
    arr = []
    for k in range(0,n):
    inp = int(input())
    li.append(inp)
    arr.append(li[0])
    for i in range(1,n):
    for j in range(i-1,i+1):
    if(li[j]<li[i]):
    arr.append(li[i])
    count1 = len(arr)
    print(count1)


  • 44_Swati Parma

    #function
    def greater_elements(arr):
    res = [arr[0]]
    for i in range(1,len(arr)):
    for j in range(0,i):
    if arr[i]arr[j]:
    res.append(arr[i])

    return(len(res))

    # main loop

    while True:
    array = []
    N = int(input(“Enter N: “))
    if N>=1 and N<=20:
    x = 0
    while x<N:

    num = int(input(f"Enter value for array[{x}]: "))
    if num 10000:
    print(“Array element out of given range”)
    continue
    else:
    array.append(num)
    x = x+1

    print(greater_elements(array))
    break

    else:
    print(“invalid input for N”)


  • Shreyanshi

    #include
    int main(){
    int i,count=1;
    int arr[5]={3,4,5,8,9};
    for(i=0;iarr[i-1]){
    count+=1;
    }
    }
    printf(“%d”,count);
    }


  • 358_Sanyogita

    #include using namespace std;
    int main()
    {
    int c,ans=1;
    int a[5]={3,4,5,8,9};
    for(int i=1;i<5;i++){
    c=0;
    for(int j=0;j<i;j++){
    if(a[j]<a[i])
    {
    c++;
    }
    }
    if(c==i){
    ans++;
    }

    }

    cout<<ans;

    return 0;
    }


  • subi.802156

    lst=[]
    n=int(input())
    for i in range (0,n):
    ele=int(input())
    lst.append(ele)
    print(lst)
    count=1
    j=0
    if lst[j]>lst[j+1]:
    count=count+1
    print(count)


  • Rohit

    #include
    using namespace std;
    int main()
    {
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i>arr[i];
    int count=1;
    for(int i=1; i<n; i++){
    if(arr[i-1]<arr[i]){
    count++;
    }
    }
    cout<<count;
    }


  • Ritika

    import java.util.*;
    class Solution
    {
    public static void main(String[] args)
    {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    arr[i]=sc.nextInt();

    int max=Integer.MIN_VALUE;
    int count=0;
    for(int i=0;imax)
    {
    max=arr[i];
    count++;
    }
    }
    System.out.println(count);
    }
    }


  • Akankshya

    l = list(map(int,input().split()))
    c1=1
    for i in range(0,len(l)-1):
    if l[i+1]>l[i]:
    c1+=1
    print(c1)


  • Nandhini

    #include
    #include
    using namespace std;

    int main()
    {
    int a[]={3,4,5,8,9};
    int x=1 , max=a[0];

    for(int i=1;imax)
    x++;
    max=a[i];
    }
    cout<<x<<endl;
    }