Showing posts with label Coding Questions. Show all posts
Showing posts with label Coding Questions. Show all posts

Tuesday, 1 July 2025

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




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

The issue isn’t your logic—it’s the lack of pattern recognition. As an SDET, knowing when to apply which pattern is the game-changer.


-x-x-x-x
👉 Refer for Quick Interview Revision: https://lnkd.in/ghvNBFPU
👉 𝗦𝘁𝗮𝗿𝘁 𝘆𝗼𝘂𝗿 end to end 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻 𝗹𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗷𝗼𝘂𝗿𝗻𝗲𝘆 𝗻𝗼𝘄 with 1:1 guidance and help in coding interview preparation: https://lnkd.in/giCxnJJ7
-x-x-x-


👉 𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻𝘀 & 𝗠𝗮𝗽𝘀 – 𝗧𝗵𝗲 𝗖𝗼𝗿𝗲 𝗼𝗳 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻 𝗗𝗮𝘁𝗮 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴

When to use: Working with test data, mapping request/response pairs, or storing UI elements.

Example:

Map locators = new HashMap<>();

locators.put("loginBtn", "//button[text()='Login']");

Coding Problem Example:

Count frequency of characters or words → Use HashMap.

👉 𝗧𝘄𝗼 𝗣𝗼𝗶𝗻𝘁𝗲𝗿𝘀 – 𝗙𝗼𝗿 𝗦𝘁𝗿𝗶𝗻𝗴𝘀, 𝗔𝗿𝗿𝗮𝘆s

When to use: Useful in validations like palindromes, comparing logs, or merging sorted logs.

Example:

int i = 0, j = arr.length - 1;

while (i < j) {

  if (arr[i] != arr[j]) return false;

  i++; j--;

}

Coding Problem Example:

Is string a palindrome? Find pairs with given sum.

👉 𝗦𝗹𝗶𝗱𝗶𝗻𝗴 𝗪𝗶𝗻𝗱𝗼𝘄 – 𝗙𝗼𝗿 𝗦𝘂𝗯𝘀𝘁𝗿𝗶𝗻𝗴𝘀 𝗮𝗻𝗱 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 𝗪𝗶𝗻𝗱𝗼𝘄𝘀

When to use: Identify performance drops, memory leaks, or longest continuous pass/fail patterns in logs.

Example:

Find the longest substring with no repeating characters.

👉 𝗦𝘁𝗿𝗶𝗻𝗴 𝗠𝗮𝗻𝗶𝗽𝘂𝗹𝗮𝘁𝗶𝗼𝗻 – 𝗙𝗼𝗿 𝗖𝗹𝗲𝗮𝗻𝘂𝗽𝘀, 𝗣𝗮𝗿𝘀𝗶𝗻𝗴, 𝗮𝗻𝗱 𝗙𝗼𝗿𝗺𝗮𝘁𝘁𝗶𝗻𝗴

When to use:When cleaning API responses, generating dynamic test data, or parsing HTML/XML/text logs.

Example:

String response = "status=200&message=Success";

String[] parts = response.split("&");

for (String part : parts) {

  String[] keyValue = part.split("=");

  System.out.println(keyValue[0] + ": " + keyValue[1]);

}

Coding Problem Example:

Reverse a string, remove duplicates, extract digits from test input, etc.

👉 𝗧𝗿𝘆-𝗖𝗮𝘁𝗰𝗵 – 𝗙𝗼𝗿 𝗦𝗮𝗳𝗲 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻 𝗖𝗼𝗱𝗲

When to use:Handling exceptions during test execution, parsing, or when dealing with unstable inputs like API responses, browser states, or external systems.

Example:

Handle potential exceptions during array access or parsing

try {

  int result = Integer.parseInt("123a"); // Will throw NumberFormatException

  System.out.println("Parsed number: " + result);

} catch (NumberFormatException e) {

  System.err.println("Invalid number format: " + e.getMessage());

}

👉 𝗥𝗲𝗴𝗲𝘅 & 𝗣𝗮𝘁𝘁𝗲𝗿𝗻 𝗠𝗮𝘁𝗰𝗵𝗶𝗻𝗴 – 𝗙𝗼𝗿 𝗟𝗼𝗴 𝗙𝗶𝗹𝗲 𝗩𝗮𝗹𝗶𝗱𝗮𝘁𝗶𝗼𝗻

Extract timestamps, validate test output format, match dynamic URLs.

Example:

Pattern p = Pattern.compile("Error: (\\d+)");

Matcher m = p.matcher(logLine);

if (m.find()) Sysout("Error Code: " + m.group(1));

-x-x-x-

📌 Watch Mock Interviews here: http://youtube.com/@automatewithsidharth 

#sidpost #qa #sdet #career #automation 

Sunday, 7 August 2022

Swap two numbers with and without using temporary variable


Swap two numbers without using temporary variable

public class SwappingNumbers {

    public static void main(String[] args) {

        float first = 10.0f, second = 14.5f;

        System.out.println("First number is " + first);
        System.out.println("Second number is " + second);

        first = first - second;
        second = first + second;
        first = second - first;

        System.out.println("--Swapping numbers--");
        System.out.println("First number = " + first);
        System.out.println("Second number = " + second);
    }
}

Now lets try to swap the numbers without using the temp variable


public class SwappingNumbers {

    public static void main(String[] args) {

        float first = 11.20f, second = 12.45f;

        // Value of the first is assigned to temporary
        float temporary = first;

        // Value of the second is assigned to first
        first = second;

        // Value of temporary is assigned to the second now
        second = temporary;

        System.out.println("First number = " + first);
        System.out.println("Second number = " + second);
    }
}

************************************************

✍️AUTHOR: LinkedIn Profile

************************************************

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employee and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employee for Automation and SDET.

For more details whatsapp 

Check below link for question and answers with the code:

Top API Interview Question 1-10

Top API INterview Questions 11-20 

Top API AUTOMATION Interview Q&A - 21-30

*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Rest-API

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/search/label/GIT

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python




Monday, 15 November 2021

Top 21 Java Coding Interview Question and Answers for QA - SDET - Testers - SDE ?

 



 Pre-requisite: How to install JDK and set Java Home path in Windows and MacOs ?

Ans: Click here for Steps

Java Interview question Set-1:
SET-01 1-10

Java Interview question Set-2:

SET-02 10-20

Java Interview question Set-3:

SET-03 21-30

11. How to reverse the first half of Array?

public class revfirsthalfIntegerArray {

    public static void main(String[] args) {

        int[] arr= {10,2,5,4,6,9,5,3};


        int len=arr.length;


        for(int i=0; i<len/4;i++)

        {

            int t = arr[i]; 

            arr[i] = arr[len/2 - i - 1]; 

            arr[len/2 - i - 1] = t; 

        }


        for(int j=0; j<len; j++)

        {

            System.out.println(arr[j]);

        }

    }

}


12. What is ModeOfArray and write the code for it?


public static void modeofarray() {


int arr[] = {1,2,3,3,4,5};

int maxnumber=-1;

int maxapperance=-1;

int result=0;


for (int i=0;i<arr.length;i++) {

int count=0;

for (int j=0;j<arr.length;j++)

                             {

if (arr[i]==arr[j]) {

count++;

}

}

if (count > maxapperance) {

maxnumber=arr[i];

maxapperance=count;

}

}

System.out.println("+" +maxnumber);

}

==> Click=Here> Pipeline Script Fundamentals

==> Click Here for Installation=> How to install Jenkins with steps?
==> Click Here :   DevOps Related Posts


13.  How to find the maximum and minimum in an ARRAY?


Ans: Click Here For Answer




14. How to find the sum of all the digits?


public static int sumofdigits(int n) {

if (n==0) {

return 0;

}

return n%10+sumofdigits(n/10);

}


15. What is median in array, define the logic and write the code?



To calculate the median first we need to sort the list in ascending or descending order. If the number of elements are even, then the median will the average of two numbers in the middle. But the number is odd then the middle element of the array after sorting will be considered as the median










 public static void medianofarray() {


int arr[]= {1,2,3,4}; //array is already sorted so no need to sort again

int arr3[]= {1,2,3,4};


if (arr.length % 2 != 0)  //if number of elements are odd

                {

System.out.println("median of array is: " + arr[arr.length/2]);


}else {


System.out.println("median of array is: " + (arr[(arr.length/2)]+arr[(arr.length/2-1)])/2.0);


}

}


16. How to merge two array in Java?


public static void mergetwoarray() {

int arr1[]= {1,5,2,4};

int arr2[]= {5,3,8,7,9};


//sort both arrays

Arrays.sort(arr1);

Arrays.sort(arr2);

int resultarray[] = new int[arr1.length+arr2.length];


int i = 0,j = 0,k=0;


while(i<arr1.length && j<arr2.length) {

if (arr1[i]<arr2[j]) {

resultarray[k++]=arr1[i++];

}

else{

resultarray[k++]=arr2[j++];

}

}

while(i<arr1.length) {

resultarray[k++]=arr1[i++];

}

while(j<arr2.length) {

resultarray[k++]=arr2[j++];

}

for (int l=0;l<resultarray.length;l++) {

System.out.println(resultarray[l]);

}

}

17.  How to find duplicates element in an array?


Click Here For Answer


18. How to find the leader in an Array?


An element is leader if it is greater than all the elements to its right side.


public static void leaderinarray() {


int arrl[]= {1,2,4,3,8,6,7,1};


for (int i=0;i<arrl.length;i++) {

int j;

for ( j=i+1;j<arrl.length;j++) {


if (arrl[i]<arrl[j]) 

                                {

break;

}

}

if (j==arrl.length) {


System.out.println(arrl[i]);

}

}

}

  •    How to convert List to array and array to list?

          Click here for Answer

  •   How to remove a SubList from a List in Java ?

    Ans: List.subList(int fromIndex, int toIndex).clear()

  • How to do Sorting of An Array?

    Click Here For Answer 

**********************

Check Selenium Interview Questions from 1 to 10 below:


Check Selenium-SDET-UIAutomation Questions set 11 to 20:
Qus Set - 11 to 20

Check Selenium-SDET-UIAutomation Questions set 21 to 30:
**********************

19.  How to Add/Join/Combine two list?


Click Here For Answers


20.  TASK: Let you have an input as "aabbBCccD" then the output should be "a2b3c3d1"

Try to find the logic and share in comments.

21. Revision :Find the second largest in an ARRAY?


public class firstsecodlargest {

public static void main(String[] args) {

int[] arr = {1,2,3,4,5,6};

int firstlargest=0;

int secondlargest=0;

int i=0;

int n= arr.length;

for (i=0;i<n;i++) 

{

if (arr[i]>firstlargest){

secondlargest=firstlargest;

firstlargest=arr[i];

}

}

System.out.println(firstlargest + "  " + secondlargest);


}}


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions

**********

Java Interview question Set-1:
SET-01 1-10

Java Interview question Set-2:

SET-02 10-20

Java Interview question Set-3:

SET-03 21-30


*************************************************

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions

All Time Popular Posts

Most Featured Post

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

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