Sunday, 23 March 2025

Remove All Occurrences of a Given Character using Two Pointer Approach

 



- ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐—ค&๐—” ๐—ฃ๐—ฎ๐—ฐ๐—ธ๐—ฎ๐—ด๐—ฒ ๐—ณ๐—ผ๐—ฟ ๐—ง๐—ฒ๐˜€๐˜ ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป & ๐—ฆ๐——๐—˜๐—ง: https://topmate.io/sidharth_shukla/605319



Problem: Remove All Occurrences of a Given Character

Problem Statement:

Given a string s and a character ch, remove all occurrences of ch from s using the two-pointer approach.

Example 1:

Input: "apple", 'p'
Output: "ale"

Example 2:

Input: "banana", 'a'
Output: "bnn"


Java Solution (Two-Pointer Approach)

public class RemoveCharacter {
public static String removeChar(String s, char ch) { char[] chars = s.toCharArray(); int j = 0; // Pointer for placing valid characters for (int i = 0; i < chars.length; i++) { if (chars[i] != ch) { chars[j] = chars[i]; j++; // Move valid character index forward } } return new String(chars, 0, j); } public static void main(String[] args) { System.out.println(removeChar("apple", 'p')); // Output: "ale" System.out.println(removeChar("banana", 'a')); // Output: "bnn" } }

Explanation (Two-Pointer Approach)

  1. Use Two Pointers:

    • i iterates through the original string.
    • j keeps track of the next position for valid characters.
  2. Skip the Character to Remove:

    • If s[i] is not equal to ch, move it to j position.
  3. Return New String Without the Removed Characters.

Time Complexity: O(n) (single pass through the string)
Space Complexity: O(n) (output string storage)

๐Ÿ”ฅ This is an easy and efficient way to remove a character from a string using two pointers! ๐Ÿš€



*** - ๐—๐—ฎ๐˜ƒ๐—ฎ ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐—ค&๐—” ๐—ฃ๐—ฎ๐—ฐ๐—ธ๐—ฎ๐—ด๐—ฒ: https://topmate.io/sidharth_shukla/1170024 - Learn Test Automation with 1:1 Guidance & Interview Preparation: https://lnkd.in/giCxnJJ7. HOLI Discount: Use Code ๐—ฆ๐—œ๐——๐—›๐—”๐—ฅ๐—ง๐—›๐Ÿญ๐Ÿฌ to get 10% Discount (ONLY for first 10 enrollments): https://lnkd.in/giCxnJJ7 ****

Friday, 21 March 2025

Rearrange String: Move Vowels to the Beginning While Keeping Order

 


Problem Statement

Given a string s, rearrange the characters such that all vowels appear at the beginning, while maintaining the relative order of the consonants. The order of vowels should also remain the same as in the original string.

Example 1

Input: "automation"
Output: "auaotmtn"

Example 2

Input: "hello"
Output: "eo hll"

Example 3

Input: "java"
Output: "aa jv"


Solution Approach

  1. Extract vowels in order.

  2. Extract consonants in order.

  3. Concatenate vowels + consonants to form the result.


You can find the video here

Java Solution


public class MoveVowelsToLeft {

    public static String moveVowelsToLeft(String s) {

        StringBuilder vowels = new StringBuilder();

        StringBuilder consonants = new StringBuilder();

        

        for (char c : s.toCharArray()) {

            if (isVowel(c)) {

                vowels.append(c);

            } else {

                consonants.append(c);

            }

        }

        return vowels.append(consonants).toString();

    }


    private static boolean isVowel(char c) {

        return "AEIOUaeiou".indexOf(c) != -1;

    }


    public static void main(String[] args) {

        System.out.println(moveVowelsToLeft("automation")); // Output: auaotmtn

        System.out.println(moveVowelsToLeft("hello"));      // Output: eo hll

        System.out.println(moveVowelsToLeft("java"));       // Output: aa jv

    }

}



Time Complexity Analysis

  • O(n), where n is the length of the string (single pass to classify characters, another pass to concatenate).



- ๐—๐—ฎ๐˜ƒ๐—ฎ ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐—ค&๐—” ๐—ฃ๐—ฎ๐—ฐ๐—ธ๐—ฎ๐—ด๐—ฒ: https://topmate.io/sidharth_shukla/1170024 - Learn Test Automation with 1:1 Guidance & Interview Preparation: https://lnkd.in/giCxnJJ7. HOLI Discount: Use Code ๐—ฆ๐—œ๐——๐—›๐—”๐—ฅ๐—ง๐—›๐Ÿญ๐Ÿฌ to get 10% Discount (ONLY for first 10 enrollments): https://lnkd.in/giCxnJJ7 - ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐—ค&๐—” ๐—ฃ๐—ฎ๐—ฐ๐—ธ๐—ฎ๐—ด๐—ฒ ๐—ณ๐—ผ๐—ฟ ๐—ง๐—ฒ๐˜€๐˜ ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป & ๐—ฆ๐——๐—˜๐—ง: https://topmate.io/sidharth_shukla/605319

Sunday, 16 March 2025

9 tips to get your LinkedIn job ready for MAANG

 Follow some steps below for your linkedin :


Here are 9 tips to get your LinkedIn job ready:




1) High Quality Profile Picture

 โ†ณ Pick a recent smiling headshot where the face is clearly visible.

 โ†ณ Use websites like PFPMaker to generate professional looking photo.

 โ†ณ Use Photofeeler website to get feedback


2) Write a killer headline

 โ†ณ One sentence to show the value you bring to the future employer

 โ†ณ Avoid using buzzwords like Motivated, Skilled, Leader

 โ†ณ Follow a template like [Role][Skills][Interest & Value Proposition]

 โ†ณ Working Professional Example: Data Scientist @ ABC | Python, PyTorch | Helping hospitals reduce their ML training cost

 โ†ณ Student Example: Pursuing Computer Science @ ABC | JavaScript, Node.js | Web Development


3) Custom LinkedIn URL

 โ†ณ The default url to your LinkedIn profile may not be very readable.

 โ†ณ Change it to something that includes your name.


4) Write a killer About section

 โ†ณ A short paragraph that speaks of your professional journey.

 โ†ณ Write case studies that showcase specific results.

 โ†ณ Use right keywords as it can boost your visibility to recruiters and hiring managers.


5) Skills Matter

 โ†ณ Linked ranks you based on the skills you put.

 โ†ณ Add 5 most relevant skills

 โ†ณ Only skills with endorsements will count

 โ†ณ Ask colleagues, friends, family & classmates for endorsement (aim for 5)


6) Leverage your Featured Section

 โ†ณ Showcase the most important work you have done.

 โ†ณ Add portfolio website, GitHub links, LinkedIn post or anything else you are proud of.


7) Fill your experience and education section

 โ†ณ Add up to date work experience and location

 โ†ณ Write bullet points for the projects you worked on.

 โ†ณ Include relevant keywords and technologies you worked with.

 โ†ณ Add your education history

 โ†ณ Include projects, links and relevant certifications


8) Engage and support Others

 โ†ณ Adding a valuable comment can generate tons of profile views.

 โ†ณ Support others in their job search journey.

 โ†ณ Leave an overall positive impression which help others grow.


9) Create Content

 โ†ณ Content is networking at scale.

 โ†ณ Your one post can reach more people than your entire connection base.

 โ†ณ It can increase your visibility and bring in more opportunities.

Monday, 3 March 2025

๐—–๐—ฟ๐—ฎ๐—ฐ๐—ธ๐—ถ๐—ป๐—ด ๐—ฆ๐——๐—˜๐—ง ๐—–๐—ผ๐—ฑ๐—ถ๐—ป๐—ด ๐—–๐—ต๐—ฎ๐—น๐—น๐—ฒ๐—ป๐—ด๐—ฒ๐˜€ โ€” ๐—Ÿ๐—ฒ๐˜โ€™๐˜€ ๐— ๐—ฎ๐—ธ๐—ฒ ๐—œ๐˜ ๐—˜๐—ฎ๐˜€๐˜†!

 





All Time Popular Posts

Most Featured Post

Java Regex Tutorial (With Examples)

  Java Regex Tutorial (With Examples) โœ… What is Regex? Regex (short for Regular Expression ) is a sequence of characters that defines a sea...