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

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

 





Saturday, 22 February 2025

TestNG Mock Interview Q&A 2025 for QA-SDET



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


******************************************** ๐Ÿ”— LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ ๐Ÿ“Œ Telegram Group: https://t.me/+FTf_NPb--GQ2ODhl ๐Ÿ“Œ Join this channel to get access to perks: https://www.youtube.com/channel/UCwuAfFzAIAKU9qVYBVHiT3A/join *********************************************



TESTNG MOCK INTERVIEW VIDEO: https://youtu.be/3-hPJf51eys









  • unticked

    What is TestNG, and how is it different from JUnit?

TestNG is a testing framework inspired by JUnit, but it offers additional features like parallel test execution, flexible test grouping, and better reporting.

  • unticked

    How do you annotate a method as a TestNG test method?

Use the @Test annotation, like this:

@Test

public void myTestMethod() {

    // Test code here

}


  • unticked

    What is the purpose of the @BeforeTest and @AfterTest annotations?

@BeforeTest is used to run setup code before any test method in the test class, and @AfterTest is used to run cleanup code after all test methods in the class.

  • unticked

    How do you perform parameterized testing in TestNG?

Use the @DataProvider annotation to supply data to a test method, like this:
java

@DataProvider(name = "myData")

public Object[][] testData() {

    return new Object[][] { { 1, 2 }, { 3, 4 } };

}


@Test(dataProvider = "myData")

public void myTestMethod(int a, int b) {

    // Test code here using a and b

}



  • unticked

    Explain how to enable parallel test execution in TestNG.

Use the parallel attribute in the <suite> tag of your testng.xml file or annotate your test class with @Listeners({ParallelListener.class}) to enable parallel execution.



  • unticked

    What is the purpose of the dependsOnMethods attribute in the @Test annotation?

It specifies that a test method depends on the successful execution of one or more other test methods before it can run.

  • unticked

    How can you prioritize test methods in TestNG?

Use the priority attribute in the @Test annotation to specify the execution order, where lower values execute first.

  • unticked

    What is the purpose of the @Parameters annotation?

@Parameters is used to specify parameters for a test method, and you can define these parameters in your testng.xml file.

  • unticked

    How do you perform group testing in TestNG?

Use the groups attribute in the @Test annotation to assign a test method to one or more groups, then include or exclude groups in your testng.xml file.

  • unticked

    How can you configure TestNG to run tests in a specific order?

You can use the preserveOrder attribute in the <suite> tag of your testng.xml file to specify that test methods should run in their declared order.

  • unticked

    Explain the purpose of the @Listeners annotation in TestNG.

@Listeners is used to add custom listeners to your test class, which can perform actions before or after test methods.

  • unticked

    What is Soft Assert in TestNG? Provide an example.

Soft Assert allows you to continue executing test steps even after an assertion fails. Here's an example:
java

SoftAssert softAssert = new SoftAssert();

softAssert.assertEquals(actual, expected);

// Continue with test steps

softAssert.assertAll(); // This will report all failures at the end


  • unticked

    Explain TestNG listeners and provide an example of a custom listener.

TestNG listeners are interfaces that allow you to customize test execution. Here's an example of a custom listener:
java

public class MyListener implements ITestListener {

    // Override listener methods like onTestStart, onTestSuccess, etc.

}


  • unticked

    How can you skip a test method in TestNG?

Use the @Test(enabled = false) annotation or the @Test annotation with enabled = true or false to skip or execute a test method.

  • unticked

    What is the purpose of the @DataProvider and @Factory annotations?

@DataProvider supplies data to test methods, while @Factory creates instances of test classes, allowing dynamic test creation.

  • unticked

    Explain TestNG's reporting capabilities and how to generate test reports.

TestNG provides built-in HTML reports. You can also integrate it with tools like ExtentReports or TestNG's IReporter interface for custom reporting.

  • unticked

    How can you set up TestNG in a Maven project?

Add the TestNG dependency in your pom.xml, and then configure your test classes and suites in a testng.xml file.

  • unticked

    What is the purpose of the @BeforeSuite and @AfterSuite annotations?

@BeforeSuite runs setup code before all test methods in a suite, and @AfterSuite runs cleanup code after all test methods.

  • unticked

    Explain how to pass parameters to a TestNG test using the testng.xml file.

Define parameters in the <parameter> tag inside <test> or <suite> tags in testng.xml, and reference them using @Parameters in your test class.

  • unticked

    How can you run TestNG tests from the command line?

Use the java -cp command with the org.testng.TestNG class and specify the testng.xml file as an argument.

  • Execute test cases from class payment?//payment is class name

<suite name="API Automation Smoke Suite">
    <test name="Automation Test Cases">
    <classes>
<class name="<nameofthepackage>.payment"/>
    </classes>
  </test>
</suite>

  • Execute multiple classes from a package using testng xml suite?


<suite name="API Automation Smoke Suite">
    <test name="Automation Test Cases">
    <classes>
<class name="apiautomationeleven.test"/>
<class name="apiautomationeleven.registration"/>
<class name="apiautomationeleven.payment"/>
    </classes>
  </test>
</suite>

  • Explain testNG annotation in sequence with real time scenario?example of @After@Before in TestNG?selenium interview qus/testng

      Click Here For Answer

  • Execute all classes from a package using testng.xml suite?


<suite name="API Automation Smoke Suite">
    <test name="Automation Test Cases">
    <packages>
      <package name="apiAutomationeleven" />
    </packages>
  </test>
</suite>

  • How to run automation suites with groups?


<suite name="API Automation Smoke Suite">
    <test name="Automation Test Cases">
    <groups>
      <run>
        <exclude name="brokenTests"  />
        <include name="SmokeSuite"  />
      </run>
    </groups>
  </test>
</suite>

  • How to use dependsOnGroups?


@Test(description="B_Users:Validate 200 status code for /users GET API",dependsOnGroups="Auth_OAUTH")

  • How you can specify your group dependencies in the testng.xml file. You use the <dependencies> tag to achieve this


<suite name="API Automation Smoke Suite">
    <test name="Automation Test Cases">
    <dependencies>
      <group name="B_User" depends-on="Auth_Oauth" />
    </dependencies>
  </test>
</suite>

  • How to use @Parameters in TestNG?


@Parameters({ "first-name" })
@Test
public void testSingleString(String firstName) {
  System.out.println("Invoked testString " + firstName);
  assert "Cedric".equals(firstName);
}


SCENARIO BASED REAL TIME

  • Question: Explain how you can achieve parallel test execution in TestNG, and what are the key attributes for parallel configuration?

Answer: Parallel execution in TestNG can be achieved using the parallel attribute at the suite, test, or method level. Key attributes include methods, tests, instances, and classes.

  • Question: How can you implement data-driven testing in TestNG, and what annotations or attributes are involved?

Answer: Data-driven testing is achieved using the @DataProvider annotation and associating it with the dataProvider attribute in the @Test annotation.

  • Question: Describe how you handle test dependencies in TestNG, and what annotations are used for this purpose.

Answer: TestNG allows dependency management using the dependsOnMethods and dependsOnGroups attributes within the @Test annotation.

  • Question: How do you group tests in TestNG, and what mechanisms are available to control the execution of specific groups?

Answer: Tests can be grouped using the @Test(groups = "group_name") annotation. Execution control involves including or excluding specific groups in the XML suite file.

  • Question: Explain the role of listeners in TestNG, and how you can generate detailed test reports using listeners.

Answer: Listeners like IInvokedMethodListener and ITestListener allow you to customize test behavior and generate detailed reports. Utilize tools like Extent Reports for enhanced reporting.

  • Question: How can you parameterize your tests in TestNG, and what is the significance of the @Parameters annotation?

Answer: Test parameterization is achieved using the @Parameters annotation in conjunction with the parameter attribute in the @Test annotation.

  • Question: What is a TestNG suite, and how can you configure and run multiple test classes using XML configuration?

Answer: A TestNG suite is a collection of test classes. Configuration is done using the XML suite file where you define test classes, groups, and parameters.

  • Question: How can you handle expected exceptions in TestNG, and what annotations are involved?

Answer: Use the @Test(expectedExceptions = Exception.class) annotation to handle expected exceptions during test execution.



  • Question: Explain the concept of soft assertions in TestNG and how they differ from traditional assertions.

Answer: Soft assertions, provided by the SoftAssert class, allow the execution of subsequent test steps even if an assertion fails, providing a comprehensive test report.

  • Question: Discuss how you integrate TestNG with Selenium for automated testing, and what are the benefits of this integration.

Answer: TestNG and Selenium integration involves creating test scripts using TestNG annotations, allowing better test organization, parallel execution, and reporting.



****

Note: This session is part of my Long-Term Mentorship Program and End-to-End Automation Course.Find the course link below to explore more and start your journey! If you're preparing for ๐—ง๐—ฒ๐˜€๐˜ ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ (๐—ฆ๐——๐—˜๐—ง) ๐—ถ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐˜€, Iโ€™ve created a Complete End-to-End Test Automation Course Kit on API+Web+Mobile+Generative AI along with unlimited 1:1 call for doubts, 4 mock interviews and 2 coding session:

๐Ÿ’ฅ Use Code ๐—ฆ๐—œ๐——๐—›๐—”๐—ฅ๐—ง๐—›๐Ÿญ๐Ÿฌ to get 10% Discount: https://lnkd.in/giCxnJJ7 ******************************************** โ‡’ ๐—–๐—ผ๐—ป๐—ป๐—ฒ๐—ฐ๐˜ ๐˜„๐—ถ๐˜๐—ต ๐—บ๐—ฒ ๐—ผ๐˜ƒ๐—ฒ๐—ฟ ๐—ฎ ๐Ÿญ:๐Ÿญ ๐—ฐ๐—ฎ๐—น๐—น: https://topmate.io/sidharth_shukla/ โ‡’ Highest Selling ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„ ๐—ค&๐—” ๐—ฃ๐—ฎ๐—ฐ๐—ธ๐—ฎ๐—ด๐—ฒ ๐—ณ๐—ผ๐—ฟ ๐—ง๐—ฒ๐˜€๐˜ ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป & ๐—ฆ๐——๐—˜๐—ง: https://topmate.io/sidharth_shukla/605319 โ‡’ Generative AI For Software Testing: https://topmate.io/sidharth_shukla/411804 ******: ๐ŸŽฏ














All Time Popular Posts

Most Featured Post

Remove All Occurrences of a Given Character using Two Pointer Approach

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