0% found this document useful (0 votes)
4 views3 pages

Logical Problems

The document outlines a series of programming exercises that cover various concepts such as summation, pattern printing, factorial calculation, prime checking, string manipulation, and algorithm implementation. Each exercise includes an example input and output to illustrate the expected results. The document emphasizes the importance of understanding problem-solving techniques rather than copying code from external sources.

Uploaded by

krish.lakhani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Logical Problems

The document outlines a series of programming exercises that cover various concepts such as summation, pattern printing, factorial calculation, prime checking, string manipulation, and algorithm implementation. Each exercise includes an example input and output to illustrate the expected results. The document emphasizes the importance of understanding problem-solving techniques rather than copying code from external sources.

Uploaded by

krish.lakhani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

​ Print sum of first n numbers


E.g. n=5, output=15 (1+2+3+4+5=15)

2.​ Print list of odd/even numbers from 1-n, where n is input.


E.g.
n = 10
even_nums = [2, 4, 6, 8, 10]
odd_nums = [1, 3, 5, 7, 9]

3.​ Use while loop and print following pattern:


n = 19
1 2 3 4 5 * * * * * 11 12 13 14 15 * * * *

Here sets are divided by 5, first set prints numbers where next set prints * so on and so
forth

If n=12, output: 1 2 3 4 5 * * * * * 11 12
If n=4, output: 1 2 3 4

4.​ Print Factorial of n


E.g n=4, output=24 (1*2*3*4=24)

5.​ Check whether number is a prime number or not


E.g. n=6, output=True

6.​ WAP to print following pattern


1
12
123

7.​ WAP to print following pattern (use while loop):


321
21
1

8.​ Generate a dictionary which stores the count of appearance of character in string
Input: aabbcdddededfg
Output= {“a”: 2, “b”: 2, “c”: 1, “d”:5, “e”:2, “f”:1, “g”:1}

9.​ Given a string of 0s and 1s print the value of string, where val(0)=1, val(1)=2
Input: 00010110
Output: 11

10.​Find the intersection of two lists


E.g List1=[1, 2, 3, 4, 5] List2=[3, 4, 6] Intersection=[3, 4]

11.​Implement a function that checks if a given string is a palindrome. A palindrome is a


word, or a sequence of characters that reads the same forward and backward.

12.​Write a function that generates the first n numbers of the Fibonacci sequence. The
Fibonacci sequence is a series of numbers where each number is the sum of the two
preceding ones, usually starting with 0 and 1. For example, the first 10 numbers in the
Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.

13.​This week's exercise is to write a function that performs a matrix transposition. Matrix
transposition means swapping the rows and columns of a matrix. For example, if you
have a 2x3 matrix:
123

456

The transposed matrix would be a 3x2 matrix:

14
25
36

14.​Write a function that implements the binary search algorithm using iteration.

15.​Write a function to solve the Two Sum problem, a popular interview question. Given an
array of integers and a target sum, return the indices of the two numbers that add up to
the target. For example, given the array [2, 7, 11, 15] and the target sum 9, the function
should return [0, 1] because 2 + 7 = 9.

16.​Write a function to find the kth largest item in an array.

17.​Valid Parentheses :
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input
string is valid.

An input string is valid if:

Open brackets must be closed by the same type of brackets.


Open brackets must be closed in the correct order.
Every close bracket has a corresponding open bracket of the same type.
Example 1:
Input: s = "()"
Output: true

Example 2:
Input: s = "()[]{}"
Output: true

Example 3:
Input: s = "(]"
Output: false

Example 4:
Input: s = "([])"
Output: true

18.​Write a code to achieve below pattern

54321
DCBA
321
BA
1

19.​

Make sure to solve all problems without copying any code from
anywhere. Note that understanding how to solve a problem is more
important than completing it by copying from somewhere.

Refer following repo and upload your solution on github/gitlab just like this:
https://github.com/RohitPatil18/Data-Structure-Algorithm-Practice/tree/main/Recursion

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy