Articles on Trending Technologies

Technical articles with clear explanations and examples

Merge Intervals in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Merging intervals is a common problem where we combine overlapping intervals in a collection. For example, if we have intervals [[1, 3], [2, 6], [8, 10], [15, 18]], the result after merging overlapping intervals would be [[1, 6], [8, 10], [15, 18]] because [1, 3] and [2, 6] overlap and merge into [1, 6]. Algorithm Steps The approach uses sorting and a stack-based method ? If the interval list is empty, return an empty list Sort intervals by their start time Initialize a stack ...

Read More

Jump Game in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 3K+ Views

The Jump Game is a classic dynamic programming problem where we need to determine if we can reach the last index of an array. Each element represents the maximum jump length from that position. Given an array like [2, 3, 1, 1, 4], we start at index 0 and can jump at most 2 positions. From index 1, we can jump at most 3 positions, and so on. The goal is to reach the last index. Algorithm Steps The greedy approach works backwards from the last index ? n := length of array A − ...

Read More

Combination Sum in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 3K+ Views

The combination sum problem involves finding all unique combinations in a given array where the numbers sum to a target value. Numbers can be reused unlimited times. For example, with candidates [2, 3, 6, 7] and target 7, the solutions are [[7], [2, 2, 3]]. Recursive Approach We'll use a recursive backtracking approach that explores all possible combinations ? class Solution: def combinationSum(self, candidates, target): result = [] self.solve(candidates, target, 0, [], result) ...

Read More

Next Permutation in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 4K+ Views

The next permutation method rearranges numbers into the lexicographically next greater permutation. If no greater permutation exists, it returns the smallest possible permutation (sorted in ascending order). The solution must be in-place without using extra memory. Examples 1, 2, 3 → 1, 3, 2 3, 2, 1 → 1, 2, 3 1, 1, 5 → 1, 5, 1 Algorithm Steps The algorithm follows these key steps − Step 1: Find the largest index i where nums[i] < nums[i+1] Step 2: If no such index exists, reverse the entire array Step ...

Read More

Parsing XML with DOM APIs in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 2K+ Views

The Document Object Model (DOM) is a cross-language API from the World Wide Web Consortium (W3C) for accessing and modifying XML documents. Unlike SAX parsers that process XML sequentially, DOM loads the entire document into memory as a tree structure, allowing random access to any element. The DOM is extremely useful for random-access applications. SAX only allows you a view of one bit of the document at a time, while DOM provides complete access to the entire document structure simultaneously. Basic DOM Parsing Here is the easiest way to quickly load an XML document and create a ...

Read More

Multithreaded Priority Queue in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 1K+ Views

The Queue module in Python allows you to create thread-safe queue objects for multithreaded applications. A priority queue processes items based on their priority rather than insertion order, making it ideal for task scheduling and resource management. Queue Methods The Queue module provides several methods to control queue operations ? get() − Removes and returns an item from the queue put() − Adds an item to the queue qsize() − Returns the number of items currently in the queue empty() − Returns True if queue is empty; otherwise, False full() − Returns True if queue is ...

Read More

Sending an HTML e-mail using Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 804 Views

When you send a text message using Python, all the content is treated as simple text. Even if you include HTML tags in a text message, it is displayed as simple text and HTML tags will not be formatted according to HTML syntax. However, Python provides the option to send an HTML message as actual HTML content. While sending an email message, you can specify a MIME version, content type and character set to send an HTML email that renders properly in email clients. Basic HTML Email Structure To send HTML email, you need to set the ...

Read More

Disconnecting Database in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 6K+ Views

When working with databases in Python, it's essential to properly close connections to free up resources and ensure data integrity. The close() method is used to disconnect from the database. Basic Syntax To disconnect a database connection, use the close() method − connection.close() Complete Example with SQLite Here's a complete example showing how to connect to a database, perform operations, and properly close the connection − import sqlite3 # Create connection connection = sqlite3.connect(':memory:') # In-memory database for demo cursor = connection.cursor() # Create a table and insert ...

Read More

Commit & RollBack Operation in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 741 Views

Database transactions in Python require careful management of commit and rollback operations. These operations ensure data integrity by allowing you to either save changes permanently or undo them completely. Understanding Transactions A transaction is a sequence of database operations that must be completed as a single unit. If any operation fails, the entire transaction can be rolled back to maintain data consistency. COMMIT Operation The commit() method finalizes all changes made during the current transaction. Once committed, changes become permanent and cannot be reverted. Example import sqlite3 # Connect to database conn ...

Read More

Database INSERT Operation in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 588 Views

The INSERT operation is used to add new records to a database table in Python. This operation requires establishing a database connection, preparing SQL statements, and handling transactions properly. Basic INSERT Statement The following example executes an SQL INSERT statement to create a record in the EMPLOYEE table ? #!/usr/bin/python import MySQLdb # Open database connection db = MySQLdb.connect("localhost", "testuser", "test123", "TESTDB") # prepare a cursor object using cursor() method cursor = db.cursor() # Prepare SQL query to INSERT a record into the database sql = """INSERT INTO EMPLOYEE(FIRST_NAME, ...

Read More
Showing 6781–6790 of 61,297 articles
« Prev 1 677 678 679 680 681 6130 Next »
Advertisements