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

Monday, 3 March 2025

𝗖𝗿𝗮𝗰𝗸𝗶𝗻𝗴 𝗦𝗗𝗘𝗧 𝗖𝗼𝗱𝗶𝗻𝗴 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲𝘀 — 𝗟𝗲𝘁’𝘀 𝗠𝗮𝗸𝗲 𝗜𝘁 𝗘𝗮𝘀𝘆!

 





Friday, 6 September 2024

Good & bad Prompt to write Selenium Tests using Generative AI with GPT

 



📌 Telegram Group: https://t.me/+FTf_NPb--GQ2ODhl
📌 YouTube channel: https://lnkd.in/gGUGmb-P

******

💛 Good & bad Prompt to write Selenium Tests using Generative AI with GPT

Scenario: Automate the validation of title for a webpage using Selenium-Java

***************************
🔺 Good Prompt Example:

👉 Prompt:

“Write a Selenium test in Java to validate the title of the webpage. Ensure that the test uses proper exception handling, includes assertions for validation, and is structured with clear comments. The test should navigate to ‘https://www.example.com', and verify that the page title is ‘Example Domain’. Additionally, the test should close the browser after execution.”

👉 Why It’s Good:

Clarity:
The prompt is clear and specific about what the test should do.

Details:
It includes additional requirements like exception handling, assertions, and closing the browser.

Context:
The webpage and title to be validated are specified.

Code Quality:
It emphasizes writing a well-structured test with comments.

*********************************
🔺 Bad Prompt Example:

👉 Prompt:
“Write a Selenium test to check a title.”

👉 Why It’s Bad:

Vagueness:
The prompt is too vague, without specifying the webpage, title, or any other details.

Lack of Detail:
It does not mention important aspects like exception handling, assertions, or browser management.

Unstructured:
The lack of structure could result in poor-quality, incomplete code.

__________
🚵‍♀️ Curious to learn more on usage of Prompts and How to use Generative AI and Code Generation tools for Software testing?
Try my sessions here: https://lnkd.in/gBjxYAPN

👾 Lets connect to discuss on use of LLM models like Sonet for Automation: https://lnkd.in/dP56a_5P

hashtag#ai hashtag#testing hashtag#softwaretesting hashtag#qualityassurance hashtag#career hashtag#sdet hashtag#qa hashtag#qaautomation hashtag#technology hashtag#llm hashtag#genai hashtag#sidpostai hashtag#sidpost

Saturday, 13 July 2024

How to use Java Overiding in Test Automation ?






💛 How to use Java Overiding in Test Automation ?



When I talk to folks in 1:1, I've noticed that many get confused about how to add new steps to the @BeforeTest method when it's set up in a base class.

Using @Override is a good way to handle this and it's a good example to mention in interviews. Just stick to relevant examples when discussing this topic during interviews and avoid giving random examples.



🔺 1️⃣ Overriding in Java:


Overriding is a concept in Java that allows a subclass to provide a specific implementation of a method that is already defined in its superclass. It enables polymorphism, where the same method name can behave differently based on the object it's called on.


🔺 Steps to implement Overriding





👉🏻 Create a Base Test Class:
Define a base test class where you initialize your WebDriver instance and set up common configurations.


public class BaseTest {
protected WebDriver driver;

@BeforeTest
public void setUp() {
// Initialize WebDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
driver = new ChromeDriver();
driver.manage().window().maximize();
}

// Other common setup methods can be added here
}



👉🏻 Override Setup Method:
Override the setUp() method in subclasses to provide specific setup actions for each test class

public class MyTest extends BaseTest {

@Override
@BeforeTest
public void setUp() {
// Call the setup method from the base class
super.setUp();

// Additional setup specific to this test class
// For example, navigating to a specific URL
driver.get("https://example.com");
}
}


In this example, the BaseTest class contains the setUp() method annotated with @BeforeTest, which initializes the WebDriver instance.

The MyTest class extends BaseTest, and the setUp() method is overridden to provide additional setup specific to the test class.

The overridden method is also annotated with @BeforeTest to ensure it executes before any test method belonging to the <test> tag in the TestNG XML suite file.



**
🔥 For a more hands-on learning experience in automation with realistic examples, consider exploring a one-on-one guided session on end-to-end automation and SDET(API+UI+Mobile+DevOps+GenerativeAI) : https://lnkd.in/giCxnJJ7

**

Introducing a curated package of Real-Time Interview Qus and Ans by an experienced Amazon SDET, covering topics like Selenium, API, Java, and more, gleaned from successful interview experiences at top companies: https://lnkd.in/gJrBGExe
**



hashtagsidpostjava hashtagsidpost hashtagjava hashtagqualityassurance hashtagtesting hashtagqa hashtagtestautomation hashtagautomation hashtagsoftwaretesting hashtagqaautomation hashtagsoftware hashtagcareer

All Time Popular Posts

Most Featured Post

𝗦𝘁𝗶𝗹𝗹 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗶𝗻𝗴 𝗿𝗼𝘂𝗻𝗱𝘀?

❓ 𝗦𝘁𝗶𝗹𝗹 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗶𝗻𝗴 𝗿𝗼𝘂𝗻𝗱𝘀? The issue isn’t your logic—it’s the lack of pattern recogniti...