Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Coding questions assignment 1, Exams of Database Programming

Coding questions assignment 1 Coding questions assignment 1

Typology: Exams

2022/2023

Uploaded on 06/24/2023

ch-subhash
ch-subhash 🇮🇳

5 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PRACTICE PROBLEMS
1) Given an arrayArrof sizeN, print secondlargest distinct
element from an array.
Example 1:
Input:
N = 6
Arr[] = {12, 35, 1, 10, 34, 1}
Output: 34
Explanation: The largest element of the
array is 35 and the second largest element
is 34.
2) Given an arrayArrofNpositive integers. Your task is to
find the elements whose value is equal to that of its index
value (Consider 1-based indexing ).
Note: There can be more than one element in the array which
have the same value as its index. You need to include every such
element's index.Follows 1-basedindexing of the array.
Example 1:
Input:
N = 5
Arr[] = {15, 2, 45, 12, 7}
Output: 2
Explanation: Only Arr[2] = 2 exists here.
3) For a given3digit number, find whether it is armstrong
number or not.AnArmstrong numberof three digits is an
pf3
pf4
pf5

Partial preview of the text

Download Coding questions assignment 1 and more Exams Database Programming in PDF only on Docsity!

PRACTICE PROBLEMS

  1. Given an array Arr of size N , print second largest distinct element from an array. Example 1: Input: N = 6 Arr[] = {12, 35, 1, 10, 34, 1} Output: 34 Explanation: The largest element of the array is 35 and the second largest element is 34.
  2. Given an array Arr of N positive integers. Your task is to find the elements whose value is equal to that of its index value ( Consider 1-based indexing ). Note : There can be more than one element in the array which have the same value as its index. You need to include every such element's index. Follows 1-based indexing of the array. Example 1: Input: N = 5 Arr[] = {15, 2, 45, 12, 7} Output: 2 Explanation: Only Arr[2] = 2 exists here.
  3. For a given 3 digit number, find whether it is armstrong number or not. An Armstrong number of three digits is an

integer such that the sum of the cubes of its digits is equal to the number itself. Return " Yes " if it is a armstrong number else return " No ". NOTE: 371 is an Armstrong number since 3^3 + 7^3 + 1^3 = 371 Example 1: Input : N = 153 Output: "Yes" Explanation : 153 is an Armstrong number since 1^3 + 5^3 + 3^3 = 153. Hence answer is "Yes".

  1. Given an array Arr of size N , swap the K th element from beginning with K th element from end. Example 1: Input: N = 8, K = 3 Arr[] = {1, 2, 3, 4, 5, 6, 7, 8} Output: 1 2 6 4 5 3 7 8 Explanation: Kth element from beginning is 3 and from end is 6.
  2. A Toeplitz (or diagonal-constant) matrix is a matrix in which each descending diagonal from left to right is constant, i.e., all elements in a diagonal are same. Given a matrix A of order N X M your task is to complete the function isToeplitz which returns true if the matrix is Toeplitz otherwise returns false

Input: N = 5, K = 16 Arr[] = {9, 7, 2, 16, 4} Output: 4 Explanation: K = 16 is found in the given array at position 4.

  1. You are given two numbers A and B. The task is to count the number of bits needed to be flipped to convert A to B. Example 1: Input: A = 10, B = 20 Output : 4 Explanation : A = 01010 B = 10100 As we can see, the bits of A that need to be flipped are 0101 0. If we flip these bits, we get 10100, which is B.
  2. Given non-zero two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value. Example 1:

Input: N = 13 , M = 4 Output: 12 Explanation: 12 is the Closest Number to 13 which is divisible by 4.

  1. Given an array of N positive integers, print k largest elements from the array. Example 1: Input: N = 5, k = 2 arr[] = {12,5,787,1,23} Output: 787 23 Explanation: First largest element in the array is 787 and the second largest is 23. Logic Of these practice set will given later in c