Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Python day-2 assignment

Uploaded by

vishwathma2
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Python day-2 assignment

Uploaded by

vishwathma2
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Create patterns using python by taking inputs

1.

A
B B
C C C
D D D D
E E E E E

2.

*
***
*****
*******
*********

3.

*
* *
* * *
* * * *

* * * * *

4.

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

5.

* * * * *
* * * *
* * *
* *
*
Solve these using python

1.Given an array of integers nums and an integer target, return indices of the two numbers such
that they add up to target. You may assume that each input would have exactly one solution, and
you may not use the same element twice. You can return the answer in any order.

Example 1: Input: nums = [2,7,11,15],

target = 9

Output: [0,1]

Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

Example 2: Input: nums = [3,2,4],

target = 6

Output: [1,2]

2. Given a sorted array of distinct integers and a target value, return the index if the target is
found. If not, return the index where it would be if it were inserted in order.
Example 1:

Input: nums = [1,3,5,6], target = 5


Output: 2

Example 2:

Input: nums = [1,3,5,6], target = 2


Output: 1

3. Code Testcase Test Result Test Result 66. Plus One Easy Topics Companies You are given a large integer
represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered
from most significant to least significant in left-to-right order. The large integer does not contain any leading
0's. Increment the large integer by one and return the resulting array of digits.

Example !:

Input: digits = [1,2,3]


Output: [1,2,4]
Explanation: The array represents the integer 123.
Incrementing by one gives 123 + 1 = 124.
Thus, the result should be [1,2,4].
Example 2:

Input: digits = [4,3,2,1]


Output: [4,3,2,2]
Explanation: The array represents the integer 4321.
Incrementing by one gives 4321 + 1 = 4322.
Thus, the result should be [4,3,2,2].

4. You are given an array prices where prices[i] is the price of a given
stock on the ith day. You want to maximize your profit by choosing a
single day to buy one stock and choosing a different day in the future to
sell that stock. Return the maximum profit you can achieve from this
transaction. If you cannot achieve any profit, return 0.

Example 1:

Input: prices = [7,1,5,3,6,4]


Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6),
profit = 6-1 = 5.
Note that buying on day 2 and selling on day 1 is not allowed because you
must buy before you sell.

Example 2:

Input: prices = [7,6,4,3,1]


Output: 0
Explanation: In this case, no transactions are done and the max profit =
0.

5. Roman numerals are represented by seven different symbols: I, V, X, L,


C, D and M.

Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
For example, 2 is written as II in Roman numeral, just two ones added
together. 12 is written as XII, which is simply X + II. The number 27 is
written as XXVII, which is XX + V + II.

Expalanation 1:

Input=’III’

Output: 3

Explanation 2:
input:’XI’

Output: 11

You might also like