Hot Topics

Tiger Analytics Solution
Technical Round
#include <bits/stdc++.h>
using namespace std;
int main() {
string s,str;
cout<<"Enter the string"<<endl;
getline(cin,s);
int len=s.length();
cout<<"Reverse string is:"<<endl;
for(int i=0;i<len;i++){
str[i]=s[len-i-1];
cout<<str[i];
}
return 0;
}
/*
OUTPUT -
Enter the string
456
Reverse string is:
654
*/
#include<stdio.h>
int main(){
int array[100],n,c,d,position,swap;
printf("Enter number of elements\n");
scanf("%d",&n);
printf("Enter %d integers\n",n);
for(c=0;c<n;c++)
scanf("%d",&array);
for(c=0;c<(n-1);c++){
position=c;
for(d=c+1;d<n;d++){
if(array[position]>array[d])
position=d;
}
if(position != c){
swap=array;
array=array[position];
array[position]=swap;
}
}
printf("Sorted list\n");
for (c = 0; c < n; c++)
{
printf("%d\n",array);
}
}
/*
OUTPUT
Enter number of elements
5
Enter 5 integers
7
8
9
3
4
Sorted list
3
4
7
8
9
*/
#include <iostream>
using namespace std;
bool isPrime(int num)
{
for (int i = 2; i <= num / 2; ++i)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
void printFirstNPrimes(int n)
{
int count = 0;
int num = 2;
while (count < n)
{
if (isPrime(num))
{
cout << num << " ";
count++;
}
num++;
}
}
int main()
{
int n;
cout << "Enter the value of n: ";
cin >> n;
cout << "The first " << n << " prime numbers are: ";
printFirstNPrimes(n);
return 0;
}
/*
OUTPUT
Enter the value of n: 10
The first 10 prime numbers are: 2 3 5 7 11 13 17 19 23 29
*/
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
cout << "Enter a string: ";
getline(cin, str);
int count[26] = {0};
for (int i = 0; i < str.length(); i++)
{
if (isalpha(str[i]))
{
count[tolower(str[i]) - 'a']++;
}
}
for (int i = 0; i < 26; i++)
{
if (count[i] != 0)
{
cout << char(i + 'a') << " appears " << count[i] << " times" << endl;
}
}
return 0;
}
/*
OUTPUT
Enter a string: codewindow
c appears 1 times
d appears 2 times
e appears 1 times
i appears 1 times
n appears 1 times
o appears 2 times
w appears 2 times
/*
SELECT *
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
LEFT JOIN (or LEFT OUTER JOIN): Returns all the rows from the left table (table1), and the matching rows from the right table (table2). The non-matching rows from the right table will be filled with NULL values.
SELECT *
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
RIGHT JOIN (or RIGHT OUTER JOIN): Returns all the rows from the right table (table2), and the matching rows from the left table (table1). The non-matching rows from the left table will be filled with NULL values.
SELECT *
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
FULL OUTER JOIN: Returns all the rows from both tables, with the matching rows combined and the non-matching rows filled with NULL values.
SELECT *
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name;
In each of these join types, the ON clause specifies the join condition, which defines the relationship between the two tables based on the values in a specific column.
def second_largest(arr):
# set the first two elements as the largest and second largest
largest = max(arr[0], arr[1])
second_largest = min(arr[0], arr[1])
# loop through the rest of the list and update the largest and second largest values
for i in range(2, len(arr)):
if arr[i] > largest:
second_largest = largest
largest = arr[i]
elif arr[i] > second_largest and arr[i] != largest:
second_largest = arr[i]
return second_largest
This algorithm uses a single loop to iterate through the list, and keeps track of the largest and second largest values as it goes. It sets the first two elements as the largest and second largest initially, and then updates them as needed as it loops through the rest of the list. The time complexity of this algorithm is O(n), making it an optimal solution for finding the second largest element in a list.




Popular Category
Hot Topics
Go through our study material. Your Job is awaiting.