Apna Hindi Tech Website Computer science के Students और Technology के बारे में जानकारी रखने वाले लोगों के लिए बहुत लाभदायक Web site है।
हमारी Website Apna Hindi Tech पर Free में Python Programming language हिंदी में सिखाई जाती है और दुनिया में जो लेटेस्ट टेक्नोलॉजी(Technology) है उसके बारे में विस्तार से बताया जाता है।
दोस्तों हमने अपनी वेबसाइट Apna Hindi Tech पर Python Programming से रिलेटेड बहुत सारे Softwares बनाना भी सिखाया है वो भी अपनी भाषा हिंदी में।
Compress The String! Hackerrank Solution Python | Compress The String Hackerrank
Hello Friends
आज हम आपको Hacker Rank पर Compress The String का कंप्लीट सॉल्यूशन बताएंगे वह भी आसान भाषा में। तो दोस्तों चलिए जानते हैं सॉल्यूशन ।
Subscribe Our YouTube Channel :- Apna Hindi Tech
Problem: Compress The String! Hackerrank Solution Python
You are given a string S. Suppose a character 'c' occurs consecutively X times in the string. Replace these consecutive occurrences of the character 'c' with (X, c) in the string.
For a better understanding of the problem, check the explanation.
Input Format
A single line of input consisting of the string S.
Output Format
A single line of output consisting of the modified string.
Constraints
All the characters of S denote integers between 0 and 9.
1<=|s|<=10^4
Sample Input
1222311
Sample Output
(1, 1) (3, 2) (1, 3) (2, 1)
Explanation
First, the character 1 occurs only once. It is replaced by (1,1). Then the character 2 occurs three times, and it is replaced by (3,2) and so on.
Also, note the single space within each compression and between the compressions.
Solution
from itertools import groupby for i,j in groupby(input()): print(tuple([len(list(j)),int(i)]),end=' ') #This Code is written by Apna Hindi Tech |
DISCLAIMER
The above hole problem statement is given by hackerrank.com but the solution is generated by the Apna Hindi Tech authority if any of the query regarding this post or website fill the following contact form.
......Thank You......
Post a Comment
Post a Comment