Programming Articles - Page 2165 of 3363

Valid Anagram in Python

Arnab Chakraborty
Updated on 28-Apr-2020 10:33:32

678 Views

Anagrams are basically all permutations of a given string or pattern. This pattern searching algorithm is slightly different. In this case, not only the exact pattern is searched, it searches all possible arrangements of the given pattern in the text. So if the inputs are “ANAGRAM” and “NAAGARM”, then they are anagram, but “cat” and “fat” are not an anagramTo solve this, we will convert the string into a list of characters, then sort them, if two sorted lists are same then they are anagram.Example (Python)Let us see the following implementation to get a better understanding − Live Democlass Solution(object):   ... Read More

Delete Node in a Linked List in Python

sudhir sharma
Updated on 31-Jul-2025 12:49:23

4K+ Views

A linked list is a linear data structure where each element is a separate object, commonly referred to as a node. Each node contains two fields: the data and a pointer to the next node in the list. In this article, we'll learn how to delete a node from a singly linked list using Python. Suppose we have a linked list with a few elements. Our task is to delete a specific node, given only access to that node - not the head of the list. For example: Input: 1 → 3 → 5 → 7 → ... Read More

How to implement the Runnable interface using lambda expression in Java?

raja
Updated on 13-Jul-2020 12:03:19

18K+ Views

The Runnable interface is a functional interface defined in java.lang package. This interface contains a single abstract method, run() with no arguments. When an object of a class implementing this interface used to create a thread, then run() method has invoked in a thread that executes separately.Syntax@FunctionalInterface public interface Runnable {  void run(); }In the below example, we can implement a Runnable interface by using an anonymous class and lambda expression.Examplepublic class RunnableLambdaTest {    public static void main(String[] args) {       Runnable r1 = new Runnable() {          @Override          public void run() { // anonymous class   ... Read More

Power of Two in C

Arnab Chakraborty
Updated on 28-Apr-2020 10:28:29

942 Views

Suppose we have a number n. We have to check whether the number is the power of 2 or not. So is n = 16, then the output will be true, if n = 12, it will be false.To solve this we will use logical operations. If we see the numbers that are the power of two then in the binary representation of that number will be the MSb is 1, and all other bits are 0. So if we perform [n AND (n – 1)], this will return 0 if n is the power of 2. If we see ... Read More

Invert Binary Tree in Python

Arnab Chakraborty
Updated on 28-Apr-2020 10:26:40

1K+ Views

Suppose we have a binary tree. our task is to create an inverted binary tree. So if the tree is like below −The inverted tree will be likeTo solve this, we will use a recursive approachif the root is null, then returnswap the left and right pointersrecursively solve left subtree and right subtreeExample (Python)Let us see the following implementation to get a better understanding − Live Democlass TreeNode:    def __init__(self, data, left = None, right = None):       self.data = data       self.left = left       self.right = right def make_tree(elements):    Tree = ... Read More

Posix character classes p{Alpha} Java regex

Maruthi Krishna
Updated on 09-Jan-2020 09:45:18

754 Views

This class matches alphabetic characters both upper case and smaller case.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example {    public static void main( String args[] ) {       //Regular expression to match lower case letters       String regex = "^\p{Alpha}+$";       //Getting the input data       Scanner sc = new Scanner(System.in);       System.out.println("Enter 5 input strings: ");       String input[] = new String[5];       for (int i=0; i

Reverse Linked List in Python

Arnab Chakraborty
Updated on 28-Apr-2020 09:57:13

566 Views

Suppose we have a linked list, we have to reverse it. So if the list is like 1 → 3 → 5 → 7, then the new reversed list will be 7 → 5 → 3 → 1To solve this, we will follow this approach −Define one procedure to perform list reversal in a recursive way as to solve(head, back)if the head is not present, then return headtemp := head.nexthead.next := backback = headif temp is empty, then return headhead = tempreturn solve(head, back)ExampleLet us see the following implementation to get a better understanding − Live Democlass ListNode:    def __init__(self, ... Read More

Posix character classes p{ASCII} Java regex.

Maruthi Krishna
Updated on 18-Jun-2025 18:55:44

897 Views

In this article, we will learn about the p{ASCII} of the POSIX character class in Java regex. What is \p{ASCII}? In Java regex, \p{ASCII} POSIX character class matches any of the characters that fall within ASCII. ASCII (American Standard Code for Information Interchange) defines a character encoding standard consisting of 128 characters (0-127). This class matches the ASCII characters within the range of \x00-\x7F. Printable characters in the \p{ASCII} of the Java Regex are: Numbers (0 to 9) Uppercase letters (A to Z) Lowercase letters (a ... Read More

Program to print Square inside a Square in C

suresh kumar
Updated on 09-Jan-2020 07:16:17

964 Views

Program DescriptionPrint Square inside a Square as shown belowAlgorithmAccept the number of rows the outer Square to be drawn Display the Outer Square with the number of rows specified by the User. Display another square inside the outer square.Example/* Program to print Square inside Square */ #include int main() {    int r, c, rows;    clrscr();    printf("Enter the Number of rows to draw Square inside a Square: ");    scanf("%d", &rows);    printf("");    for (r = 1; r

Program to print solid and hollow square patterns in C

suresh kumar
Updated on 13-Jul-2020 12:04:35

927 Views

Program DescriptionIn geometry, a square is a regular quadrilateral, which means that it has four equal sides and four equal angles.Solid and Hollow Square will appear as shown belowAlgorithmFor Solid Square −Accept the Number of Rows from the user to draw the Solid Square For each Row, Print * for each Column to draw the Solid SquareFor Hollow Square −Accept the Number of Rows from the user to draw the Hollow Square For the First and Last Row, Print * for each Column For the Remaining Rows, Print * for the first and Last Column.Example/* Program to print hollow and ... Read More

Advertisements