Python day-2 assignment
Python day-2 assignment
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.
target = 9
Output: [0,1]
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:
Example 2:
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 !:
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:
Example 2:
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