Table of contents Recursive exponential Recursive max Recursive multiplication Recursive sum Recursive average Recursive uppercase Recursive exponential Given two exponential numbers with the same base, the multiplication is another exponential number with the same base but we add the exponents. We can utilize this observation and define a recursive exponential formula. If (n) is even

Table of contents Circular linked list Linked list nth node from the end Reverse linked list Reverse linked list recursively Circular linked list This is a typical interview question. Given a singly linked list. Write a function that detects if the linked list is circular (has a loop) which means the last node points to

Problem Given a string of comma separated numbers, we want to convert that string to a Python list of integers Solution The idea here is to split the string into tokens then convert each token to an integer. We can do that in a couple of ways. Let us see how… Use a list comprehension

Introduction Removing blank lines from a file requires two steps. First, we need to loop through the file lines. Second, check if the line is empty. In Python, there are different ways to perform the loop and check. Let us summarize that… Loop method There are multiple styles to iterate through file lines. Here are

Problem In this Python code snippet, we are going to implement a naive run length encoding algorithm to compress strings Solution The idea is very simple, text has redundancy so instead of sending plain text, we can compress text by sending characters and their counts. This is a typical text processing problem that gets asked

Problem Write a Python function that checks if two strings are rotation of each other Solution Rotating a string means inserting a number of characters from the end of the string to the beginning of the string. Any easy trick to check if two strings are rotation of each other is to concatenate one string

Problem Implement an algorithm in Python to check if a given input string is a permutation of another palindrome string Solution If the number of occurrences of all characters in the string is even then the input string can be a permutation of a palindrome string. There is only once exception which is the character

Problem Write an algorithm in Python to check if two strings are permutations of each other Solution Let us differentiate between permutations and combinations. An easy way is to think about permutations in terms of lists and combinations in terms of sets. Take a look at the code snippets below… Code Thanks for visiting. Please

Problem Given a string of characters. Implement an algorithm in Python to check if the string has all unique characters. Solution One solution is to get the unique characters in the string using a set. If the length of the input string is the same as the length of the set then the string has

Table of contents One item at a time Pickle object serialization Write string to file Write json to file Write lines Using print List to string References Save list to file in Python Saving data structures such as lists to permanent storage for later retrieval is a common practice in computer programming. This technique is