Skip to main content

Posts

Showing posts with the label tutorials

Majority Element in an Array

Majority Element in an Array Given an integer array nums of size n , the task is to find the majority element . A majority element is defined as the element that appears more than ⌊n / 2⌋ times in the array. It is guaranteed that the majority element always exists. Problem Example Input: nums = [3, 2, 3] Output: 3 Input: nums = [2,2,1,1,1,2,2] Output: 2 Approach 1: Using Counter (Easy to Understand) A straightforward approach is to count the frequency of each element and return the one with the maximum count. Python Code from collections import Counter class Solution: def majorityElement(self, nums): freq = Counter(nums) max_count = max(freq.values()) for key in freq: if freq[key] == max_count: return key Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) Although this solution is simple and readable, it us...

Solution: LeetCode 27 — Remove Element

LeetCode 27 — Remove Element Solution 1 (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: p = 0 for i in nums: if i != val: nums[p] = i p += 1 return p Solution 2(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...

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, ...

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. ...

instagram reel video download

instagram reel video download Instagram is owned by meta, aka Facebook. Since Instagram introduced Instagram feature in 2020 after ban of TikTok in India, it has a large audience and users wants to consume same and short content, so they prefer Instagram shorts. Nowadays, Instagram has many influencers and with huge followers, more than a million. And influencers creates reels in order to get more reach, and if you want to download your favorite influencers reels, so this article is for you and if you want to download Instagram Reels of your friend, so again this blog is also for you. Do you also have the question that- Can I download Instagram Reels? So my straight forward answer is yes! Why not? You can! It is possible to download Instagram Reels. If you are trying to download reels from your own feed, so it is very straight forward process, we will talk about it in another article. In this article, I will tell you how to download another person's account's feed's reel, ...

How many phone numbers are in your name? Find out now what this

How many phone numbers are  in your name? Find out now what this  The DoT portal is also known as Telecom Analytics for Fraud Management and Consumer Protection (TAFCOP). According to the rules issued by DoT, a citizen can only issue 9 cell phone numbers from their Aadhar card.  @image credit- 123rf.com We all know how much cheating has increased today. Especially the cases of SIM card fraud or Aadhar card fraud are at their peak. People don't know what tricks he uses for his own benefit.There are these types of scams that need to be recognized. Do you know how many cell phone numbers are registered in your name? If not, then today's article is for you. Because today we are going to tell you how to know how many cell phone numbers are registered in your name. If you want to know how many   mobile numbers are registered in your name, you can easily find out.You can find out through the Department of Telecommunications (DoT) portal. From here you can know how many...

Hidden Features of Android

 Hidden Features of Android   Dive into the Android  framework with us and explore some cool secrets.   Android is a great little operating system. It is packed with great features, amazing hacks and tricks to save your time.   But how much do you really know about your phone or tablet? Sure, you can make  calls and text, but we bet there's something in this article  you didn't know about.Read on to find out!     1. Enable developer mode     Ok, this is one of the most popular tricks, but it's still important, so we'll include it.   Go to Settings > About phone and tap  your phone's build number seven times. A countdown will appear on the screen, followed by a message that says "Congratulations, you are now a developer". 2. Change animation speed   For the most part, the latest Android phones already feel very fast. However, some low-end phones only have 4GB of RAM, and in extreme...

How do I recover permanently deleted files from my computer?

 How do I recover permanently deleted files from my computer?   How to Recover Deleted Videos and Photos From Laptop: If you have accidentally deleted important files like important documents, videos, important photos, presentation or any movie on your computer or laptop, then today's blog I worked hard for you guys. written. Because in today's blog, I will tell you how to recover this data, then your problem will definitely be solved. So let's know in this blog today how to do this. I am sure that all of you must be using laptop or desktop. Everyone does school work. As soon as the storage of laptop or computer becomes more, due to which we keep all our photos and videos backed up in it. And sometimes people make mistakes and human beings are the mannequin of mistakes, in such a situation the files get deleted and you must be very sad. If it has ever happened to you that any of your important documents, entertainment movie collection or important pictures have been delete...

how to record call on whatsapp?

 how to record call on whatsapp? WhatsApp owned by Meta has not provided any way for the feature of call recording of WhatsApp calls, but with the help of third party applications, you can record the call of WhatsApp calls. You can download this application from Google Play Store. By the way, you will definitely find many applications in Google Playstore for call recording of WhatsApp calls. The WhatsApp application is most commonly used for messaging. It is owned by Facebook i.e. today's meta company, this meta is the same company whose CEO is Mark Elliot Zuckerberg and at the same time this company also owns many big social media including WhatsApp such as Instagram, Facebook etc. Provides many services like voice calling, messaging and video calling all over the world. And at the same time, it ensures that the messages sent or received are end-to-end encrypted. One of the most famous features of this app is that you can call or message any person in a single click. And...