Software Development Exam  >  Software Development Notes  >  Python- Mastering Development in Python  >  Mastering Development in Python : Assignment 3

Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development PDF Download

Q1: Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "".

A string is palindromic if it reads the same forward and backward.

Example 1:

Input: words = ["abc","car","ada","racecar","cool"]

Output: "ada"

Explanation: The first string that is palindromic is "ada".

Note that "racecar" is also palindromic, but it is not the first.

Example 2:

Input: words = ["notapalindrome","racecar"]

Output: "racecar"

Explanation: The first and only string that is palindromic is "racecar".

Example 3:

Input: words = ["def","ghi"]

Output: ""

Explanation: There are no palindromic strings, so the empty string is returned.

 Constraints:

1 <= words.length <= 100

1 <= words[i].length <= 100

words[i] consists only of lowercase English letters.

Ans:  Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development


Q2:  You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter.

Your task is to make s a palindrome with the minimum number of operations possible. If there are multiple palindromes that can be made using the minimum number of operations, make the lexicographically smallest one.

A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.

Return the resulting palindrome string.

Example 1:

Input: s = "egcfe"

Output: "efcfe"

Explanation: The minimum number of operations to make "egcfe" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "efcfe", by changing 'g'.

Example 2:

Input: s = "abcd"

Output: "abba"

Explanation: The minimum number of operations to make "abcd" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is "abba".

Example 3:

Input: s = "seven"

Output: "neven"

Explanation: The minimum number of operations to make "seven" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "neven".

 Constraints:

1 <= s.length <= 1000

s consists of only lowercase English letters.

Ans: Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development


Q3:

You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.

Return the merged string.

Example 1:

Input: word1 = "abc", word2 = "pqr"

Output: "apbqcr"

Explanation: The merged string will be merged as so:

word1:  a   b   c

word2:    p   q   r

merged: a p b q c r

Example 2:

Input: word1 = "ab", word2 = "pqrs"

Output: "apbqrs"

Explanation: Notice that as word2 is longer, "rs" is appended to the end.

word1:  a   b 

word2:    p   q   r   s

merged: a p b q   r   s

Example 3:

Input: word1 = "abcd", word2 = "pq"

Output: "apbqcd"

Explanation: Notice that as word1 is longer, "cd" is appended to the end.

word1:  a   b   c   d

word2:    p   q 

merged: a p b q c   d

Constraints:

1 <= word1.length, word2.length <= 100

word1 and word2 consist of lowercase English letters.

Ans: Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development


Q4: 

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

Example 1:

Input: nums = [-4,-1,0,3,10]

Output: [0,1,9,16,100]

Explanation: After squaring, the array becomes [16,1,0,9,100].

After sorting, it becomes [0,1,9,16,100].

Example 2:

Input: nums = [-7,-3,2,3,11]

Output: [4,9,9,49,121]

 Constraints:

1 <= nums.length <= 104

-104 <= nums[i] <= 104

nums is sorted in non-decreasing order.

Ans: Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development



Q5:  Given an array of integers nums, half of the integers in nums are odd, and the other half are even.

Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.

Return any answer array that satisfies this condition.

Example 1:

Input: nums = [4,2,5,7]

Output: [4,5,2,7]

Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.

Example 2:

Input: nums = [2,3]

Output: [2,3]

 Constraints:

2 <= nums.length <= 2 * 104

nums.length is even.

Half of the integers in nums are even.

0 <= nums[i] <= 1000

Ans: Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development



 

The document Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development is a part of the Software Development Course Python- Mastering Development in Python.
All you need of Software Development at this link: Software Development
Are you preparing for Software Development Exam? Then you should check out the best video lectures, notes, free mock test series, crash course and much more provided by EduRev. You also get your detailed analysis and report cards along with 24x7 doubt solving for you to excel in Software Development exam. So join EduRev now and revolutionise the way you learn!
Sign up for Free Download App for Free
8 videos|5 docs

Up next

Up next

Explore Courses for Software Development exam
Related Searches

pdf

,

study material

,

Exam

,

Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development

,

Free

,

Extra Questions

,

Summary

,

video lectures

,

Sample Paper

,

Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development

,

Objective type Questions

,

practice quizzes

,

ppt

,

Previous Year Questions with Solutions

,

Mastering Development in Python : Assignment 3 | Python- Mastering Development in Python - Software Development

,

past year papers

,

Important questions

,

shortcuts and tricks

,

MCQs

,

Viva Questions

,

Semester Notes

,

mock tests for examination

;