Check if a string can become empty by recursive deletion using Slicing Last Updated : 03 Jan, 2025 Comments Improve Suggest changes Like Article Like Report To check if the string "geeksforgeeks" can become empty by recursively deleting occurrences of a specific substring, we can use string slicing and recursion. Here's how to do it for the string "geeksforgeeks" with a specific substring, say "geeks".Let's understand this with the help of an example: Python def can_become_empty_with_slicing(string, substring): # If the string is empty, it can be considered successfully reduced to empty if not string: return True # Check if the substring exists at any position index = string.find(substring) if index != -1: # Remove the substring using slicing and recursively check return can_become_empty_with_slicing(string[:index] + string[index + len(substring):], substring) # If the substring is not found, and the string is not empty, return False return False # Example test case input_string = "geeksforgeeks" substring = "geeks" # Call the function and store the result result = can_become_empty_with_slicing(input_string, substring) print(result) OutputFalse Explanation:Base case: If the string becomes empty (i.e., not string), the function returns True, indicating that the string has successfully been reduced to an empty string.Recursive case: The function checks if the substring "geeks" exists in the string. If it does, it removes the first occurrence of the substring and recursively calls itself with the modified string.If the substring isn't found, the function returns False, indicating the string can't be reduced to empty by removing the substring. Comment More infoAdvertise with us Next Article Must Do Coding Questions - Topic-wise S Shashank Mishra Follow Improve Article Tags : DSA python-string Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like