SlideShare a Scribd company logo
1 of 2
Download to read offline
Repeated	String
Lilah	has	a	string,	 ,	of	lowercase	English	letters	that	she	repeated	infinitely	many	times.
Given	an	integer,	 ,	find	and	print	the	number	of	letter	 a 's	in	the	first	 	letters	of	Lilah's	infinite	string.
Input	Format
The	first	line	contains	a	single	string,	 .	
The	second	line	contains	an	integer,	 .
Constraints
For	 	of	the	test	cases,	 .
Output	Format
Print	a	single	integer	denoting	the	number	of	letter	 a 's	in	the	first	 	letters	of	the	infinite	string	created	by
repeating	 	infinitely	many	times.
Sample	Input	0
aba
10
Sample	Output	0
7
Explanation	0	
The	first	 	letters	of	the	infinite	string	are	 abaabaabaa .	Because	there	are	 	 a 's,	we	print	 	on	a
new	line.
Sample	Input	1
a
1000000000000
Sample	Output	1
1000000000000
Explanation	1	
Because	all	of	the	first	 	letters	of	the	infinite	string	are	 a ,	we	print	
on	a	new	line.
def​ ​repeatedString​(s, n):
​'''Computes and returns total number of occurrences of the character 'a'
in the prefix of length n of an infinitely repeating string.
Parameters:
s - Input string which is considered to be repeated infinitely.
n - The first number of letters to be considered for counting number
of occurrences of the character 'a' in the infinite string.
Returns:
Total number of occurrences of the character 'a'.
'''
​# Length of string.
len_str = len(s)
​# Number of repeated strings to be considered.
num_strs = n//len_str
​# Remainder: Let's consider an example - s = 'abc' and n = 11.
​# Therefore, the string to be considered for finding the number
​# of occurrences of 'a' will be: 'abcabcabcab'. The string is
​# repeating 3 times(abcabcabc). Now, remaining letters are only 2(ab).
​# Therefore, length of remaining letters is calculated as below syntax.
remainder = n%len_str
​# Counter to count number of a's from given string.
count1 = 0
​# Counter to count a's from the remaining set of letters. In the end, it
​# will be used to calculate total number of a's in the string.
count2 = 0
​for​ i ​in​ range(len_str):
​# Calculating number of occurrences of character 'a' from the given string
​if​ s[i] == ​'a'​:
count1 += 1
​# Calculating number of occurrences from remaining letters
​# if they exist.
​if​ s[i] == ​'a'​ ​and​ i < remainder:
count2 += 1
​# Calculating total number of a's in the string
total = count1*num_strs + count2
​return​ total
# Testing
print(repeatedString(​'aba'​, 10))

More Related Content

What's hot

Database system environment ppt.
Database system environment ppt.Database system environment ppt.
Database system environment ppt.yhen06
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMSPadamNepal1
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointersSamiksha Pun
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database ModelShishir Aryal
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its functionFrankie Jones
 
ARCHITECTURE OF DBMS (1).ppt
ARCHITECTURE OF DBMS (1).pptARCHITECTURE OF DBMS (1).ppt
ARCHITECTURE OF DBMS (1).pptShivareddyGangam
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLEVraj Patel
 
database recovery techniques
database recovery techniques database recovery techniques
database recovery techniques Kalhan Liyanage
 
E-R Diagram of College Management Systems
E-R Diagram of College Management SystemsE-R Diagram of College Management Systems
E-R Diagram of College Management SystemsOmprakash Chauhan
 
Dbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design IssueDbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design IssueAmiya9439793168
 
Er model ppt
Er model pptEr model ppt
Er model pptPihu Goel
 
Codd's rules
Codd's rulesCodd's rules
Codd's rulesMohd Arif
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)yourbookworldanil
 
5 the relational algebra and calculus
5 the relational algebra and calculus5 the relational algebra and calculus
5 the relational algebra and calculusKumar
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational AlgebraAmin Omi
 

What's hot (20)

Database system environment ppt.
Database system environment ppt.Database system environment ppt.
Database system environment ppt.
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
ARCHITECTURE OF DBMS (1).ppt
ARCHITECTURE OF DBMS (1).pptARCHITECTURE OF DBMS (1).ppt
ARCHITECTURE OF DBMS (1).ppt
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
database recovery techniques
database recovery techniques database recovery techniques
database recovery techniques
 
E-R Diagram of College Management Systems
E-R Diagram of College Management SystemsE-R Diagram of College Management Systems
E-R Diagram of College Management Systems
 
Dbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design IssueDbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design Issue
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Er model ppt
Er model pptEr model ppt
Er model ppt
 
Codd's rules
Codd's rulesCodd's rules
Codd's rules
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)
 
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORYGE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
 
SQL
SQL SQL
SQL
 
5 the relational algebra and calculus
5 the relational algebra and calculus5 the relational algebra and calculus
5 the relational algebra and calculus
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 

Similar to HackerRank Repeated String Problem

Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfChapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfDrIsikoIsaac
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfpaijitk
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiSowmya Jyothi
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptxPadreBhoj
 
For this assignment, download the A6 code pack. This zip fil.docx
For this assignment, download the A6 code pack. This zip fil.docxFor this assignment, download the A6 code pack. This zip fil.docx
For this assignment, download the A6 code pack. This zip fil.docxalfred4lewis58146
 
Acm aleppo cpc training third session
Acm aleppo cpc training third sessionAcm aleppo cpc training third session
Acm aleppo cpc training third sessionAhmad Bashar Eter
 

Similar to HackerRank Repeated String Problem (12)

Python strings
Python stringsPython strings
Python strings
 
Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfChapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdf
 
python_strings.pdf
python_strings.pdfpython_strings.pdf
python_strings.pdf
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Python data handling
Python data handlingPython data handling
Python data handling
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdf
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptx
 
For this assignment, download the A6 code pack. This zip fil.docx
For this assignment, download the A6 code pack. This zip fil.docxFor this assignment, download the A6 code pack. This zip fil.docx
For this assignment, download the A6 code pack. This zip fil.docx
 
Acm aleppo cpc training third session
Acm aleppo cpc training third sessionAcm aleppo cpc training third session
Acm aleppo cpc training third session
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 

More from Isham Rashik

Text Preprocessing - 1
Text Preprocessing - 1Text Preprocessing - 1
Text Preprocessing - 1Isham Rashik
 
9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...Isham Rashik
 
Fundamentals of Cryptography - Caesar Cipher - Python
Fundamentals of Cryptography - Caesar Cipher - Python Fundamentals of Cryptography - Caesar Cipher - Python
Fundamentals of Cryptography - Caesar Cipher - Python Isham Rashik
 
Python 3.x Dictionaries and Sets Cheatsheet
Python 3.x Dictionaries and Sets CheatsheetPython 3.x Dictionaries and Sets Cheatsheet
Python 3.x Dictionaries and Sets CheatsheetIsham Rashik
 
Operations Management - BSB INC - Case Study
Operations Management - BSB INC - Case StudyOperations Management - BSB INC - Case Study
Operations Management - BSB INC - Case StudyIsham Rashik
 
Corporate Finance - Disney Sea Park Project
Corporate Finance - Disney Sea Park ProjectCorporate Finance - Disney Sea Park Project
Corporate Finance - Disney Sea Park ProjectIsham Rashik
 
Questionnaire - Why women entrepreneurs are happier than men?
Questionnaire - Why women entrepreneurs are happier than men?Questionnaire - Why women entrepreneurs are happier than men?
Questionnaire - Why women entrepreneurs are happier than men?Isham Rashik
 
Human Resource Management - Different Interview Techniques
Human Resource Management - Different Interview TechniquesHuman Resource Management - Different Interview Techniques
Human Resource Management - Different Interview TechniquesIsham Rashik
 
Python 3.x File Object Manipulation Cheatsheet
Python 3.x File Object Manipulation CheatsheetPython 3.x File Object Manipulation Cheatsheet
Python 3.x File Object Manipulation CheatsheetIsham Rashik
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3Isham Rashik
 
Android Application Development - Level 2
Android Application Development - Level 2Android Application Development - Level 2
Android Application Development - Level 2Isham Rashik
 
Android Application Development - Level 1
Android Application Development - Level 1Android Application Development - Level 1
Android Application Development - Level 1Isham Rashik
 
Managerial Skills Presentation - Elon Musk
Managerial Skills Presentation - Elon MuskManagerial Skills Presentation - Elon Musk
Managerial Skills Presentation - Elon MuskIsham Rashik
 
Operations Management - Business Process Reengineering - Example
Operations Management - Business Process Reengineering - ExampleOperations Management - Business Process Reengineering - Example
Operations Management - Business Process Reengineering - ExampleIsham Rashik
 
Lighting Design - Theory and Calculations
Lighting Design - Theory and CalculationsLighting Design - Theory and Calculations
Lighting Design - Theory and CalculationsIsham Rashik
 
Linear Control Hard-Disk Read/Write Controller Assignment
Linear Control Hard-Disk Read/Write Controller AssignmentLinear Control Hard-Disk Read/Write Controller Assignment
Linear Control Hard-Disk Read/Write Controller AssignmentIsham Rashik
 
Transformers and Induction Motors
Transformers and Induction MotorsTransformers and Induction Motors
Transformers and Induction MotorsIsham Rashik
 
Three phase balanced load circuits and synchronous generators
Three phase balanced load circuits and synchronous generatorsThree phase balanced load circuits and synchronous generators
Three phase balanced load circuits and synchronous generatorsIsham Rashik
 
Circuit Breakers for Low Voltage Applications
Circuit Breakers for Low Voltage ApplicationsCircuit Breakers for Low Voltage Applications
Circuit Breakers for Low Voltage ApplicationsIsham Rashik
 
Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet Isham Rashik
 

More from Isham Rashik (20)

Text Preprocessing - 1
Text Preprocessing - 1Text Preprocessing - 1
Text Preprocessing - 1
 
9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...
 
Fundamentals of Cryptography - Caesar Cipher - Python
Fundamentals of Cryptography - Caesar Cipher - Python Fundamentals of Cryptography - Caesar Cipher - Python
Fundamentals of Cryptography - Caesar Cipher - Python
 
Python 3.x Dictionaries and Sets Cheatsheet
Python 3.x Dictionaries and Sets CheatsheetPython 3.x Dictionaries and Sets Cheatsheet
Python 3.x Dictionaries and Sets Cheatsheet
 
Operations Management - BSB INC - Case Study
Operations Management - BSB INC - Case StudyOperations Management - BSB INC - Case Study
Operations Management - BSB INC - Case Study
 
Corporate Finance - Disney Sea Park Project
Corporate Finance - Disney Sea Park ProjectCorporate Finance - Disney Sea Park Project
Corporate Finance - Disney Sea Park Project
 
Questionnaire - Why women entrepreneurs are happier than men?
Questionnaire - Why women entrepreneurs are happier than men?Questionnaire - Why women entrepreneurs are happier than men?
Questionnaire - Why women entrepreneurs are happier than men?
 
Human Resource Management - Different Interview Techniques
Human Resource Management - Different Interview TechniquesHuman Resource Management - Different Interview Techniques
Human Resource Management - Different Interview Techniques
 
Python 3.x File Object Manipulation Cheatsheet
Python 3.x File Object Manipulation CheatsheetPython 3.x File Object Manipulation Cheatsheet
Python 3.x File Object Manipulation Cheatsheet
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
Android Application Development - Level 2
Android Application Development - Level 2Android Application Development - Level 2
Android Application Development - Level 2
 
Android Application Development - Level 1
Android Application Development - Level 1Android Application Development - Level 1
Android Application Development - Level 1
 
Managerial Skills Presentation - Elon Musk
Managerial Skills Presentation - Elon MuskManagerial Skills Presentation - Elon Musk
Managerial Skills Presentation - Elon Musk
 
Operations Management - Business Process Reengineering - Example
Operations Management - Business Process Reengineering - ExampleOperations Management - Business Process Reengineering - Example
Operations Management - Business Process Reengineering - Example
 
Lighting Design - Theory and Calculations
Lighting Design - Theory and CalculationsLighting Design - Theory and Calculations
Lighting Design - Theory and Calculations
 
Linear Control Hard-Disk Read/Write Controller Assignment
Linear Control Hard-Disk Read/Write Controller AssignmentLinear Control Hard-Disk Read/Write Controller Assignment
Linear Control Hard-Disk Read/Write Controller Assignment
 
Transformers and Induction Motors
Transformers and Induction MotorsTransformers and Induction Motors
Transformers and Induction Motors
 
Three phase balanced load circuits and synchronous generators
Three phase balanced load circuits and synchronous generatorsThree phase balanced load circuits and synchronous generators
Three phase balanced load circuits and synchronous generators
 
Circuit Breakers for Low Voltage Applications
Circuit Breakers for Low Voltage ApplicationsCircuit Breakers for Low Voltage Applications
Circuit Breakers for Low Voltage Applications
 
Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet
 

Recently uploaded

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

HackerRank Repeated String Problem

  • 1. Repeated String Lilah has a string, , of lowercase English letters that she repeated infinitely many times. Given an integer, , find and print the number of letter a 's in the first letters of Lilah's infinite string. Input Format The first line contains a single string, . The second line contains an integer, . Constraints For of the test cases, . Output Format Print a single integer denoting the number of letter a 's in the first letters of the infinite string created by repeating infinitely many times. Sample Input 0 aba 10 Sample Output 0 7 Explanation 0 The first letters of the infinite string are abaabaabaa . Because there are a 's, we print on a new line. Sample Input 1 a 1000000000000 Sample Output 1 1000000000000 Explanation 1 Because all of the first letters of the infinite string are a , we print on a new line.
  • 2. def​ ​repeatedString​(s, n): ​'''Computes and returns total number of occurrences of the character 'a' in the prefix of length n of an infinitely repeating string. Parameters: s - Input string which is considered to be repeated infinitely. n - The first number of letters to be considered for counting number of occurrences of the character 'a' in the infinite string. Returns: Total number of occurrences of the character 'a'. ''' ​# Length of string. len_str = len(s) ​# Number of repeated strings to be considered. num_strs = n//len_str ​# Remainder: Let's consider an example - s = 'abc' and n = 11. ​# Therefore, the string to be considered for finding the number ​# of occurrences of 'a' will be: 'abcabcabcab'. The string is ​# repeating 3 times(abcabcabc). Now, remaining letters are only 2(ab). ​# Therefore, length of remaining letters is calculated as below syntax. remainder = n%len_str ​# Counter to count number of a's from given string. count1 = 0 ​# Counter to count a's from the remaining set of letters. In the end, it ​# will be used to calculate total number of a's in the string. count2 = 0 ​for​ i ​in​ range(len_str): ​# Calculating number of occurrences of character 'a' from the given string ​if​ s[i] == ​'a'​: count1 += 1 ​# Calculating number of occurrences from remaining letters ​# if they exist. ​if​ s[i] == ​'a'​ ​and​ i < remainder: count2 += 1 ​# Calculating total number of a's in the string total = count1*num_strs + count2 ​return​ total # Testing print(repeatedString(​'aba'​, 10))