Skip to main content

Posts

Solution: LeetCode 27 — Remove Element

LeetCode 27 — Remove Element Solution (Optimal) This version is in-place, single-pass, O(n) time and O(1) space. It preserves the relative order of kept elements. class Solution: def removeElement(self, nums: List[int], val: int) -> int: l, r = 0, len(nums) - 1 while l return l Common Mistakes Modifying the list while iterating with for x in nums plus remove or pop — this changes indices and skips elements. Returning the modified list instead of the new length . Trying to maintain order with an algorithm designed to minimize writes (e.g., two-pointer-swap) without noting that order won’t be preserved. Using extra memory (creating a new list) when interview expects in-place solution. Edge Cases Empty array: nums = [] → return 0 . All elements equal to val : return 0 . No elements equal to val : return original length. Mix of occurrences: ...

LeetCode 88 Explained: Four Approaches, Mistakes, Fixes & the Final Optimal Python Solution

Evolving My Solution to “Merge Sorted Array” A practical, beginner-friendly walkthrough showing four versions of my code (from a naive approach to the optimal in-place two-pointer solution). Includes explanations, complexity and ready-to-paste code. Problem Summary You are given two sorted arrays: nums1 with size m + n (first m are valid) nums2 with size n Goal: Merge nums2 into nums1 in sorted order in-place . Version 1 — Beginner Approach (Extra List) I merged into a new list then copied back. Works, but not in-place and uses extra memory. class Solution: def merge(self, nums1, m, nums2, n): result = [] p1 = 0 p2 = 0 for _ in range(m+n): if p1 >= m: result.extend(nums2[p2:n]) break elif p2 >= n: result.extend(nums1[p1:m]) break elif nu...

Introducing CodeMad: Your Ultimate Universal IDE with Custom Shortcuts

Introducing CodeMad: Your Ultimate Multi-Language IDE with Custom Shortcuts Welcome to the world of CodeMad, your all-in-one Integrated Development Environment (IDE) that simplifies coding and boosts productivity. Developed in Python, CodeMad is designed to make your coding experience smoother and more efficient across a variety of programming languages, including C, C++, Java, Python, and HTML. Whether you're a beginner or an experienced programmer, CodeMad is your go-to tool. In this blog, we'll dive deep into the workings of CodeMad, highlighting its unique features and easy installation process. The Power of Shortcuts CodeMad's intuitive interface is built around a set of powerful keyboard shortcuts that make coding a breeze. Here are some of the key shortcuts you'll find in CodeMad: Copy (Ctrl+C) : Duplicate text with ease. Paste (Ctrl+V) : Quickly insert copied content into your code. Undo (Ctrl+Z) and Redo (Ctrl+Y) : Correct mistakes and s...

Python Project: AI Based Assignment Completer

Python Project: AI-Based Assignment Completer A small suite of Python scripts that generate C programs from prompts, create outputs and collect code into a .docx file. 1. File 1 — generator (generate C files) Notes: Replace the API key placeholder on the line where openai.api_key is set with your own key, or set openai.api_key elsewhere in your environment. Create a prompt.txt file in the same directory with one question per line. Create a folder named programms in the same directory — generated C files will be placed there. The Python code (unchanged): import os import openai class Ai: number=0 def automatedquery(self, query): '''this f(x) returns the responce generated by cahtgpt''' openai.api_key = "Your Api Key Here!" response = openai.Completion.create( model="text-davinci-003", prompt=query, ...

How to increase your PC speed.

  Here are some tips for increasing the speed of your computer: Remove unnecessary programs and files: Go through your computer and delete any programs or files that you no longer need. This can free up space on your hard drive and speed up your computer. Clean up your hard drive: Use a disk cleanup tool to remove temporary files and other unnecessary items from your hard drive. This can help free up space and speed up your computer. Run a virus scan: Viruses and malware can slow down your computer and even damage important files. Run a full virus scan to make sure your computer is free of any malware. Keep your computer updated: Make sure your operating system and all of your programs are up-to-date. This can help fix bugs and improve the performance of your computer. Add more RAM: If your computer is running slowly, adding more RAM can help speed it up. This is because more RAM allows your computer to run more programs at the same time without slowing down. Run a disk defragment:...

Run python scripts on android using termux. How to install python in Termux.

How to install python in Termux.  Termux is a powerful terminal emulator for Android that allows you to run command-line programs and tools. One of the most popular programming languages, Python, can be installed in Termux and used for a variety of purposes, such as web development, data analysis, and machine learning. Termux is a powerful terminal emulator for Android that allows users to run command-line programs and tools on their mobile devices. It provides a full Linux-style environment, complete with a package manager and a range of pre-installed tools. One of the benefits of using Termux is that it makes it easy to install and use Python on Android devices. With just a few commands, you can install the latest version of Python and start using it to write and run scripts, or to use Python libraries in your own projects. Python and Termux are a powerful combination that can be used for a wide range of purposes, such as web scraping, data analysis, and machine learning. Whether...

How to install windows 10 on the computer

How to install windows 10 on the computer?   Installing Windows 10 can be a simple process if you have the right tools and follow the correct steps. Here's a guide on how to do it: First, you'll need to download the Windows 10 installation media. You can do this by going to the Microsoft website and following the prompts to create a bootable USB drive or DVD. Once you have the installation media, you'll need to boot from it. To do this, you'll need to change the boot order in your computer's BIOS settings. Restart your computer, and press the key that allows you to enter the BIOS settings (usually F2, F10, or DEL). Navigate to the boot order menu, and set the USB drive or DVD as the first boot option. Save the changes and exit the BIOS. Your computer should now boot from the installation media. You'll be asked to choose your language and other preferences. Click "Next" to continue. On the next screen, you'll see the "Install Now" button. ...