-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek_7.txt
88 lines (80 loc) · 3.5 KB
/
week_7.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
resource url?
QUESTION ----------------
Coders here is a simple task for you, Given string str. Your task is to check whether it is a binary string or not by using python set.Examples: Input: str = "01010101010"Output: YesInput: str = "REC101"Output: No
------------------ANSWER
string=input()
s=set(string)
if s=={'0','1'}or s=={'0'}or s=={'1'}:
print("Yes")
else:
print("No")
------------------------------
QUESTION ----------------
Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.There is only one repeated number in nums, return this repeated number. Solve the problem using set.Example 1:Input: nums = [1,3,4,2,2]Output: 2Example 2:Input: nums = [3,1,3,4,2]Output: 3
------------------ANSWER
n = list(map(int,input().split()))
n_set=set()
for num in n:
if num in n_set:
print(num)
break
else:
n_set.add(num)
------------------------------
QUESTION ----------------
The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'.For example, "ACGAATTCCG" is a DNA sequence.When studying DNA, it is useful to identify repeated sequences within the DNA.Given a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order. Example 1:Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
Output: ["AAAAACCCCC","CCCCCAAAAA"]
Example 2:Input: s = "AAAAAAAAAAAAA"
Output: ["AAAAAAAAAA"]
------------------ANSWER
from collections import Counter
string = input()
windows = [string[i: i + 10] for i in range(0,len(string) - 10)]
counter = Counter(windows)
for i in counter:
if counter[i] > 1:
print(i)
------------------------------
QUESTION ----------------
Given a tuple and a positive integer k, the task is to find the count of distinct pairs in the tuple whose sum is equal to K.
------------------ANSWER
t = tuple(map(int, input().split(','))) # Input the tuple as comma-separated integers
K = int(input())
s = set(t)
count = 0
for x in s:
if K - x in s:
count += 1
result = count // 2
print(result)
------------------------------
QUESTION ----------------
Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.In the American keyboard:the first row consists of the characters "qwertyuiop",the second row consists of the characters "asdfghjkl", andthe third row consists of the characters "zxcvbnm". Example 1:Input: words = ["Hello","Alaska","Dad","Peace"]
Output: ["Alaska","Dad"]
Example 2:Input: words = ["omk"]
Output: []
Example 3:Input: words = ["adsdf","sfd"]
Output: ["adsdf","sfd"]
------------------ANSWER
# Define the sets for each row of the keyboard
row1 = set('qwertyuiop')
row2 = set('asdfghjkl')
row3 = set('zxcvbnm')
# Input the number of words
num_words = int(input())
# Flag to check if any word is found
found = False
# Iterate through each word
for _ in range(num_words):
word = input()
word_lower = word.lower()
# Check if all characters of the word are in the same row
if all(char in row1 for char in word_lower) or \
all(char in row2 for char in word_lower) or \
all(char in row3 for char in word_lower):
print(word)
found = True
# If no words are found, print "No words"
if not found:
print("No words")
------------------------------