![profile pic](https://preparesh-arbpfvdsfpcdg8a0.z01.azurefd.net/images/technologies/python.png)
![profile pic](https://preparesh-arbpfvdsfpcdg8a0.z01.azurefd.net/images/technologies/python.png)
Given an array of integers, you need to solve two problems:
- Find the maximum difference between two elements such that the larger element appears after the smaller element.
- Find the minimum number of steps required to sort the array in non-decreasing order where a step is defined as incrementing any element by 1.
Implement these two functionalities in Python.
Please sign-in to view the solution
Given an array of integers, an equilibrium point is an index such that the sum of elements at lower indices is equal to the sum of elements at higher indices. Write a function in Python to find the first equilibrium point in the array. If no such point exists, return -1.
Example:
Input:
[1, 3, 5, 2, 2]
Output:
2 (since 1 + 3 = 2 + 2)
Please sign-in to view the solution
Write a Python function to print all prime numbers up to a given limit. Explain your approach briefly.
Please sign-in to view the solution
Given an array of strings, write a function to encode the entire array into a single string, and another function to decode this single string back into the original array of strings.
Requirements:
- The encoded string should be as compact as possible.
- Ensure no ambiguity in delimiting the individual strings.
Example:
array = ["apple", "banana", "cherry"]
encoded_str = encode(array)
decoded_array = decode(encoded_str)
assert decoded_array == array
Please sign-in to view the solution
Given an array, write a function to generate all possible permutations of the array elements.
Requirements:
- The function should return a list of all possible permutations.
- Each permutation should be in the form of a list.
Example:
array = [1, 2, 3]
permutations = generate_permutations(array)
assert permutations == [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
Please sign-in to view the solution
Given a sorted array of integers, write a function to remove any duplicates. Describe your algorithm, provide the code implementation, and list how you would test your program.
Please sign-in to view the solution
Describe different types of testing and explain how to implement them in real-time scenarios. Provide examples and tools that can be used.
Please sign-in to view the solution
Provide test data for a program whose functionality is to find the second smallest number in a set. Include various cases such as typical, edge, and erroneous scenarios to ensure comprehensive testing of the function.
Please sign-in to view the solution
Explain and provide examples of software testing and development coding questions that involve basic data structures. Consider questions that cover arrays, linked lists, stacks, and queues. Provide a detailed solution for each example.
Please sign-in to view the solution
You are analyzing sales data and notice that there are anomalies in the data for several key regions over the past quarter. Specifically, the sales figures for certain products are either too high or too low compared to historical data. Describe a step-by-step approach to identify and address these anomalies using SQL and Python.
Please sign-in to view the solution
Write a Python function that takes a string and returns a new string that contains only the characters at even indices. Demonstrate the function with an example.
Please sign-in to view the solution
Write a function in any programming language you know to automate a test.
Please sign-in to view the solution
Given a string, write a function in Python to remove all duplicate characters while preserving the original order of characters.
Please sign-in to view the solution
Write a function in Python to traverse an array both from back to front and vice versa. Print the elements in both orders.
Please sign-in to view the solution
As a software engineer, you are tasked with optimizing a given piece of code to improve its efficiency in terms of Big O notation. Describe at least five general strategies you would employ to enhance the code's performance.
Please sign-in to view the solution
You are tasked with writing a function that compares patterns in two strings. Specifically, the function should determine if two strings follow the same pattern of characters and return True
or False
. Consider the following example:
Pattern: 'abba'
String1: 'hello world world hello'
String2: 'hi there there hi'
In this case, your function should return True
because both strings follow the pattern 'abba'. Implement this function in Python.
Please sign-in to view the solution
Write a method in Python that reads a text file and returns a dictionary where the keys are words and the values are the count of occurrences of each word in the file.
Requirements:
- Ignore case (e.g., 'Word' and 'word' should be counted as the same word).
- Ignore punctuation.
- Ensure the function handles large files efficiently.
Example:
# Assuming the file 'sample.txt' contains the text: 'Hello world! Hello everyone.'
result = word_count('sample.txt')
assert result == {'hello': 2, 'world': 1, 'everyone': 1}
Please sign-in to view the solution
Given two integer arrays, write a function to find the common numbers as well as the different numbers in both arrays. Return two lists: one with the common numbers and one with the different numbers.
Requirements:
- The common numbers should appear only once in the result, even if they appear multiple times in the input arrays.
- The different numbers should include all numbers that are present in one array but not the other.
Example:
array1 = [1, 2, 3, 4, 4]
array2 = [3, 4, 5, 6]
common, different = find_common_and_different(array1, array2)
assert common == [3, 4]
assert different == [1, 2, 5, 6]
Please sign-in to view the solution
Write a function in Python that performs two tasks:
- Given a linked list, convert it into a 2D array where each row contains two consecutive linked list values.
- Given a 2D array, convert it back into a linked list where each element points to the next.
Requirements:
- Assume the linked list has an even number of elements.
- The 2D array should have a shape [n/2, 2], where n is the length of the linked list.
Example:
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
# Linked list: 1 -> 2 -> 3 -> 4
head = ListNode(1, ListNode(2, ListNode(3, ListNode(4))))
# Task 1
array = linked_list_to_2d_array(head)
assert array == [[1, 2], [3, 4]]
# Task 2
new_head = array_to_linked_list(array)
# Validate new_head to be a linked list: 1 -> 2 -> 3 -> 4
assert new_head.val == 1
assert new_head.next.val == 2
assert new_head.next.next.val == 3
assert new_head.next.next.next.val == 4
Please sign-in to view the solution
Given millions of rows of numerical data, write a method to efficiently find the median value. The data cannot be loaded into memory all at once due to its size.
Requirements:
- The method should handle data that does not fit into memory.
- The solution should be efficient in terms of time and space complexity.
Example:
# Let's assume we have a method `read_streaming_data` that yields data row by row
def find_median_large_dataset(streaming_data):
# Implementation here...
# Example usage
streaming_data = read_streaming_data('large_dataset.csv')
median = find_median_large_dataset(streaming_data)
print(median)
Please sign-in to view the solution
Given an array of integers, write a function to find the maximum and the second largest maximum values in the array.
Requirements:
- The function should have a runtime complexity of O(n).
- Describe how you would test this function.
Example:
array = [3, 2, 1, 5, 4]
max_val, second_max_val = find_max_and_second_max(array)
assert max_val == 5
assert second_max_val == 4
Please sign-in to view the solution
Write test cases for a function which implements the addition of two numbers.
Please sign-in to view the solution
Given a string, remove the consecutively repeated characters. For example - aabbbcabcbb
to cabc
.
Please sign-in to view the solution
Write a code to convert a string such as aaabbccdaa
to a3b2c2d1a2
.
Please sign-in to view the solution
Compress a string. For example, aaabbbcccccddddd
should be converted to a3b3c4d4
.
Please sign-in to view the solution
Imagine you are a Data Analyst at Amazon working on improving the product recommendation algorithm. You are given a dataset with user_id, product_id, rating, and timestamp. Your task is to identify the top 5 most popular products (most purchased) in the last 30 days. What steps would you take to solve this problem using Python and SQL?
Please sign-in to view the solution
Given a string and a character, write a function in Python to count the number of times the character occurs in the string.
Please sign-in to view the solution
Given a sentence, write a function in Python to find the longest palindromic substring within it. A palindrome is a string that reads the same backward as forward.
Please sign-in to view the solution
Given an array of integers, implement a function in Python that returns a new array where each element at index i
is the product of all the elements in the original array except the one at i
. You are not allowed to use division. Optimize for O(n) time complexity. Provide test cases to validate your solution.
Please sign-in to view the solution
Given an array of integers where every element appears twice except for one, write a function to find that single element. Explain the approach and also provide a code solution in Python.
Please sign-in to view the solution
Given two unsorted arrays of integers, write a function to determine if the arrays contain the same elements, regardless of their order. Explain your approach and provide a Python code solution.
Please sign-in to view the solution
Write a Python function to sort three numbers. Explain your approach briefly.
Please sign-in to view the solution
Write test cases for widgets that pop out when you perform a Google Search. For example, the calculator widget when searching 'tan x', or the unit converter widget when searching 'convert 60kgs to pounds'. The test cases should cover general scenarios testing this functionality of invoking widgets via the search toolbar.
Requirements:
- Each test case should verify that the correct widget is rendered based on the search query.
- You do not need to go into details of individual widget functionalities, but rather ensure that the correct widget appears.
Example:
Test Case 1:
- Input: 'tan x'
- Expected Result: Calculator widget should appear.
Test Case 2:
- Input: 'convert 60kgs to pounds'
- Expected Result: Unit converter widget should appear.
Provide a few more example test cases to illustrate the point.
Please sign-in to view the solution
You are analyzing sales data and notice that there are anomalies in the data for several key regions over the past quarter. Specifically, the sales figures for certain products are either too high or too low compared to historical data. Describe a step-by-step approach to identify and address these anomalies using SQL and Python.
Please sign-in to view the solution
Given an array, locate the three greatest numbers and print their product.
Please sign-in to view the solution
Find the number of occurrences of each character in a given string.
Please sign-in to view the solution
Given an array of strings, find the common prefix among them.
Please sign-in to view the solution
Given a 2D array (matrix) of integers, write a function that applies the following transformation:
Flip the matrix horizontally (i.e., reverse the order of elements in each row).
Implement this transformation in Python and apply it to the given matrix.
Example:
Input:
[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
Output:
[
[3, 2, 1],
[6, 5, 4],
[9, 8, 7]
]
Please sign-in to view the solution
Given a binary tree, write a function to invert the binary tree (i.e., swap the left and right children of every node).
Implement this transformation in Python.
Example:
Input:
4
/ \
2 7
/ \ / \
1 3 6 9
Output:
4
/ \
7 2
/ \ / \
9 6 3 1
Please sign-in to view the solution
Given a linked list and an integer value k, write a function to return the kth element from the end of the linked list.
Requirements:
- You can assume k is a valid integer that will not exceed the length of the linked list.
- The function should handle linked lists efficiently.
Example:
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
# Linked list: 1 -> 2 -> 3 -> 4 -> 5
head = ListNode(1, ListNode(2, ListNode(3, ListNode(4, ListNode(5)))))
k = 2
result = find_kth_from_end(head, k)
assert result == 4 # The 2nd element from the end is 4
Please sign-in to view the solution
Describe how you would test the functionality of the Google Search Bar. Consider different scenarios and edge cases that need to be verified.
Please sign-in to view the solution
Write a program in Python to find the depth of a binary search tree without using recursion.
Please sign-in to view the solution
Write a program that takes a list of integers and a list of pairs of indices as input. The program should swap the elements at the given indices for each pair. Provide an example to illustrate the functionality.
Please sign-in to view the solution
Write a program that takes a 2D matrix as input and outputs the elements in spiral order. Provide an example to illustrate the functionality.
Please sign-in to view the solution
Write a routine in Python to parse a log file. The routine should extract and display all log entries that match a specific log level (e.g., ERROR, WARNING, INFO). Provide an example of how the routine processes a sample log file and filters entries based on a given log level.
Please sign-in to view the solution
Write a Python program to read through a text file, extract telephone numbers and email addresses, and save them into another file. Provide an example of how the program works, including sample input and the expected output.
Please sign-in to view the solution
State and explain some key functions of popular machine learning libraries such as Scikit-Learn, TensorFlow, and PyTorch. Provide examples of how these functions are used.
Please sign-in to view the solution
Write a program to group anagrams from a given list of strings. This is a common problem on LeetCode.
Please sign-in to view the solution
Write a function in Python to find the sum of all digits in a given number.
Please sign-in to view the solution
- Given a number, find the nearest palindrome.
- Given an array of length
n
containing numbers between 1 to 99, print the last two digits of the result after multiplying alln
numbers in the array.
Please sign-in to view the solution
Write a function in Python to check if the binary representation of a given number is a palindrome. A palindrome is a sequence that reads the same backward as forward.
Please sign-in to view the solution
How would you automate an API that retrieves bank and card holder information when given a credit card number as input?
Please sign-in to view the solution
- Write test cases for a video calling app on a mobile device.
- Write a program to find consecutive duplicate letters in each word of the sentence and print the sentence without duplicate letters.
- Find a series of numbers in an array which gives the sum value as 3.
Please sign-in to view the solution
Write a function in Python and Java to find the union of two strings. The union of two strings includes all unique characters present in either of the strings.
Please sign-in to view the solution
Given a list of integers, write a function to group all positive numbers, zeros, and negative numbers together without using any additional data structures like sets or collections. Maintain the original relative order of elements within the same group. For example, if the input list is [4, -1, 0, 3, -2, 0, 1]
, the output should be [4, 3, 1, 0, 0, -1, -2]
.
Please sign-in to view the solution
Given an unsorted list of integers, write a function to find the second largest value in the list. You are not allowed to sort the list or use any built-in functions that directly identify the largest or second largest values. For example, if the input list is [3, 1, 4, 1, 5, 9, 2, 6]
, the output should be 6
.
Please sign-in to view the solution
You are given a list of customer IDs in a Python list, which might contain duplicates. Write a Python function that uses a HashSet to determine if there are any duplicates in the list.
Please sign-in to view the solution
Write a Python script using Selenium WebDriver to print all the links (<a>
tags) from a web page. The script should open the specified web page, find all the links, and then print out the text and the URL for each link.
Please sign-in to view the solution
Write a function in Python to find a pair of numbers in an array such that their product is the maximum possible.
Please sign-in to view the solution
Write a function in Python to check if the first string is an anagram of the second string. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Please sign-in to view the solution
Write a function in any language that will print "AN" if a number is divisible by 8, "ANIM" if divisible by 16, and "ANIMAL" if divisible by 32.
Please sign-in to view the solution
Write a class representation of a deck of cards (52 cards) in Python and Java that includes shuffle and deal methods.
Please sign-in to view the solution
Write a function to reverse a linked list in groups of K (any number) in Python and Java.
Please sign-in to view the solution
Given a string sentence, write a function to reverse the order of words without using any library functions for reversing strings or splitting words. For example, if the input string is 'The quick brown fox', the output should be 'fox brown quick The'.
Please sign-in to view the solution
As a software engineer at Oracle, explain the concept of JSONPath and its usage. Provide an example demonstrating how to query JSON data using JSONPath expressions in Python. Include examples that show how to select specific elements, access array elements, and filter nodes.
Please sign-in to view the solution
You are given a singly linked list and you need to write a function in Python to reverse the linked list. Assume the linked list node is defined as follows:
class ListNode:
def __init__(self, value=0, next=None):
self.value = value
self.next = next
Write a function reverse_linked_list
that takes the head of the linked list as an argument and returns the new head of the reversed list.
Please sign-in to view the solution
Explain how to replace parts of a string using regular expressions (regex) in Python. Provide example code demonstrating the use of the re.sub
function for this purpose.
Please sign-in to view the solution
Write a function to find the shortest path between two points on a 2D matrix. The matrix contains cells that can either be empty (0) or blocked (1). You can move up, down, left, or right but cannot move through blocked cells.
Please sign-in to view the solution
What is binary search?
Please sign-in to view the solution
What is a Binary Search Tree? What is a Doubly Circular Linked List?
Please sign-in to view the solution
Write a function in Python and Java to check if parentheses are closed correctly in a given string. The function should support different types of parentheses: ()
, {}
, and []
.
Please sign-in to view the solution
Given a list of integers ranging from 1 to 100, write a function to identify and return the prime numbers from the list. For example, if the input list is [10, 15, 23, 50, 7]
, the output should be [23, 7]
.
Please sign-in to view the solution
Given a string containing both numbers and letters, write a Python function to extract and return the vowels, sorted in reverse alphabetical order. For example, given the string 'h3ll04a2bci27u8o1e', the expected output is 'uoiea'.
Please sign-in to view the solution
As a Business Analyst at Oracle, you need to analyze a large volume of trace logs to identify and extract error patterns for system diagnostics. Describe the process, tools, and technologies you would utilize. Additionally, provide an example Python script to extract error patterns from a log file.
Please sign-in to view the solution
As a software engineer at Oracle, explain the key concepts of Docker and its advantages. Provide a simple example demonstrating how to create a Dockerfile for a Python application, build a Docker image, and run a Docker container. Additionally, explain how to share your Docker image via Docker Hub.
Please sign-in to view the solution
You are developing a class hierarchy in Python for a financial application. You have a superclass called Transaction
with a method process()
. You have a subclass called InternationalTransaction
that extends Transaction
. Override the process()
method in InternationalTransaction
to perform additional processing but ensure that it still calls the process()
method from Transaction
.
Please sign-in to view the solution
You are required to automate the submission of a web form using Selenium WebDriver in Python. The form has the following fields:
- Text input field with
id="username"
- Password input field with
id="password"
- Submit button with
id="submit"
Write a Python script using Selenium to fill out the form and submit it, handling potential delays in the page load using WebDriverWait.
Please sign-in to view the solution
Write a code snippet in Python to handle pop-up windows using Selenium WebDriver. The code should demonstrate how to switch to the pop-up, perform an action such as accepting or dismissing it, and then switch back to the main window.
Please sign-in to view the solution
Describe the method to check if there is a loop in a linked list. Provide the algorithm and example code in Python.
Please sign-in to view the solution
- Write a function to find the closest palindrome number to a given number.
- Write a function to determine if an array contains duplicate numbers.
- Write a function to print numbers in a rhombus shape:
1 121 12321 121 1
Please sign-in to view the solution
Given an array with numbers from 1 to 5, write a function in Python to subtract one number from each index.
Please sign-in to view the solution
As a Quality Assurance Engineer at Oracle, you are tasked with designing a test automation framework using Object-Oriented Programming (OOP) principles. Explain how you would apply OOP concepts such as inheritance, polymorphism, encapsulation, and abstraction in building the framework. Provide a simple example in Python demonstrating these OOP principles in the context of test automation.
Please sign-in to view the solution
You are working on a Python project with several modules and packages. Over time, some modules may become obsolete and unused. How would you identify all the unused modules in the project?
Please sign-in to view the solution
Write a program in Python to reverse a given string. The program should take a string as input and return the reversed string as output.
Please sign-in to view the solution