instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Given a binary tree, find the height of the tree and return the maximum sum of values of nodes at any level in the tree. | codefeedback |
Describe a sorting algorithm that works by putting elements in the right place, with a time complexity of O(n^2) and a space complexity of O(1). | codefeedback |
Implement a function to reverse a singly linked list in-place. The function should have a time complexity of O(n) and should not use any additional data structures. | codefeedback |
Iterate through the given array and print the prime numbers. | codefeedback |
Implement a priority queue with the following methods:
1. `insert(element, priority)`: Inserts an element into the priority queue with the given priority.
2. `delete_min()`: Removes and returns the element with the minimum priority from the priority queue. If multiple elements have the same minimum priority, any one o... | codefeedback |
Using the given code, construct a json request payload with the following requirements:
1. The payload should include an additional key-value pair for the person's address, where the address is an object with the keys "street", "city", and "state".
2. The payload should include an array of objects for the person's hob... | codefeedback |
Write a Python function to calculate the sum of the areas of a given list of circles, where each circle is defined as a dictionary containing 'radius' and 'x' as keys. The 'radius' of each circle must be a positive integer. The 'x' coordinate of each circle must be a positive float. The number of circles in the list mu... | codefeedback |
Using Java, create a program to find the maximum sum of a sub-array within a given array, taking into consideration the constraint that the sub-array should not contain any negative numbers. Additionally, optimize your solution to have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Given a JSON object with nested objects and arrays, write a JavaScript function to flatten the object keys.
#Example Input:#
{
"name": {
"first": "John",
"last": "Smith"
},
"age": 25,
"hobbies": ["reading", "painting"],
"address": {
"street": "123 Main St",
"city": "... | codefeedback |
Create a SQLite query to find the names, ages, and addresses of the youngest and oldest customers. Additionally, sort the results in descending order based on their ages. | codefeedback |
Using JavaScript and HTML, create an interactive web page that displays a list of strings taken from the user's inputs. The strings should be displayed in alphabetical order. Additionally, each string should be displayed with a checkbox next to it, allowing the user to select multiple strings. The selected strings shou... | codefeedback |
Design a SQL query to find the top 3 customers with the highest spendings in the year 20 | codefeedback |
Write a Python program to delete a given key from a dictionary, while also keeping track of the number of times each key is deleted. The program should store the deleted keys and their corresponding count in a separate dictionary. Additionally, the program should handle cases where the given key is not present in the d... | codefeedback |
Create a database structure in MySQL for a shopping cart application containing a user, product, order, and category table. Each product can belong to multiple categories, and each category can have multiple products. | codefeedback |
Design a MongoDB database for an e-commerce platform with the following collections:
1. Customers collection: This collection should contain the following fields:
- name (string): The name of the customer.
- city (string): The city where the customer resides.
- phone (string): The phone number of the customer... | codefeedback |
Write a Java class to represent a student record with the following fields: student_name, grade, score, and a list of subject scores. The subject scores should be stored in a separate class with fields for subject_name and subject_score.
The class should include the following methods:
1. A method to calculate the aver... | codefeedback |
Develop a function in Java that, given a positive number n (1 <= n <= 10), returns the factorial of that number. The function should also handle negative numbers and throw an IllegalArgumentException with a custom error message if n is negative. Additionally, the function should check if n is a prime number and print a... | codefeedback |
Create a class in C++ representing a 2D vector which has components (x, y). The class should include the following functionalities:
1. Addition: Implement a method that takes another 2D vector as input and returns the sum of the two vectors.
2. Subtraction: Implement a method that takes another 2D vector as input and ... | codefeedback |
Use a regular expression to find all the capital letters in the provided string, and count how many times each capital letter appears. Return a dictionary where the keys are the capital letters and the values are the corresponding counts.
text = "This is a string with multiple Capital A's and B's" | codefeedback |
Create a function to calculate the nth Fibonacci number, where n is a positive integer. The function should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
How would you write a function to find the mode in an array of numbers, considering the possibility of multiple modes in the array?
nums = [2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 9, 10, 10] | codefeedback |
Write a SQL query to show the name, date of birth, and address of all employees born after 1st January 1980, who are currently working in the sales department and have more than 5 years of experience. | codefeedback |
Generate a python class for calculating prime numbers up to n, where n is an input parameter.
Requirements:
- The class should have a method named `calculate_primes` that takes an integer `n` as input.
- The method should return a list of prime numbers up to `n`.
- The class should handle edge cases such as negative i... | codefeedback |
Provide a context-free grammar to generate strings that contain only a's and b's and which have the same number of a's as b's, and have at least one occurrence of the substring "aba". | codefeedback |
Generate a SQL query that selects all the fruit names from a table, sorted in descending order by the number of times each fruit has been purchased. Additionally, exclude any fruits that have not been purchased at least 10 times. | codefeedback |
Create a function that returns a list of the top n highest valued elements in a given array. The function should take two parameters - the array and the value of n. The function should return the top n elements in descending order of their values.
For example:
arr = [7, 5, 8, 4, 9, 6, 1, 3, 2]
n = 4
The function shou... | codefeedback |
Implement a quicksort algorithm in your preferred programming language. Explain the steps involved in the algorithm and analyze its time complexity. Provide a detailed explanation of the partitioning process used in the quicksort algorithm and discuss any possible optimizations. | codefeedback |
Given a Binary search tree, write a C++ program to find the lowest common ancestor (LCA) of two given nodes in the BST. Additionally, the program should be able to handle a situation where the two given nodes are not present in the BST. | codefeedback |
Write a program that parses the following JSON structure and stores each element into a variable. Additionally, calculate the total cost by multiplying the quantity of each item by its respective cost and display the result.
{
"items": ["apple", "orange", "banana"],
"quantity": [4, 2, 7],
"cost": [2.00, 1.50, 3.0... | codefeedback |
Make the following sentence compliant with PEP 8.
Write a program that takes a list of integers as input and prints the sum of all the even numbers in the list. The program should be written in accordance with PEP 8 guidelines and should have a time complexity of O(n) and space complexity of O(1). The input list shoul... | codefeedback |
How would you create a for-loop in Python to iterate through all the prime numbers from 1 to 100? | codefeedback |
Calculate the minimum, maximum, and average of the following array. Additionally, find the second largest and second smallest elements in the array.
Reference Code:
```python
def calculate_stats(array):
min_val = max_val = sum_val = array[0]
for i in range(1, len(array)):
if array[i] < min_val:
... | codefeedback |
Calculate the greatest common factor of 18 and 12. Your solution must use recursion and cannot use the modulo operator. | codefeedback |
Increase the difficulty of the given programming test question by:
- Adding a constraint that the iterative solution must use constant space complexity, i.e., it cannot use any additional data structures besides a few variables.
- Specifying that the time complexity should be O(n), where n is the input number.
- Restri... | codefeedback |
Deploy a model server on AWS Lambda to serve a machine learning model using a custom-built serverless framework. | codefeedback |
Write an SQL query that updates the values in the 'exampleTable' so that all the numbers in the 'number' column are increased by 10. Additionally, for every row where the number is divisible by 5, multiply the number by 2. | codefeedback |
Generate a balanced ternary search tree data structure in Python. | codefeedback |
Generate a sentence using GPT-3 that includes at least three synonyms for the word "developed." GPT-3 is an AI language model created by OpenAI. | codefeedback |
Increase the difficulty of the given programming test question by adding additional steps and logic:
1. Create an empty dictionary named `dict1`.
2. Iterate over each tuple in `list1`.
3. Extract the first element of the tuple as the key and the second element as the value.
4. Check if the key already exists in `dict1... | codefeedback |
Create a for loop to print out the square of the numbers between 10 and 20, but only if the number is divisible by 3. | codefeedback |
Write a Bash script to accept two command line arguments (username and password) and echo them out. Additionally, the script should check if the password meets the following criteria:
- The password must be at least 8 characters long.
- The password must contain at least one uppercase letter, one lowercase letter, and ... | codefeedback |
Describe a classification problem in machine learning and explain the steps involved in solving it. | codefeedback |
Design an Android application to store a user's sensor data and display real-time graphs of the sensor readings. | codefeedback |
Write a class with a method named 'helloWorld' that takes in a string parameter and returns the string with all vowels replaced by the corresponding vowel's next letter in the alphabet. | codefeedback |
Generate an HTML page with a table that displays data from a database. The table should have sortable columns and allow users to filter the data based on certain criteria. Additionally, implement functionality to dynamically update the table without refreshing the entire page. | codefeedback |
Create an SQL query that returns all customers in New York state who have made at least 3 purchases in the last 6 months, with the most recent purchase being within the last month. | codefeedback |
Define a class in C++ to represent a point in 4-dimensional space. | codefeedback |
Write a function in Java that can be used to search an array and return the index of the element. The function should also handle cases where the element is not present in the array and return -1 in such cases. Additionally, the function should be able to handle arrays with duplicate elements and return the index of th... | codefeedback |
Create a Python script that sets the value of a variable from the command-line, but the value must be encrypted using a custom encryption algorithm before being assigned to the variable. | codefeedback |
Create an object-oriented C# program that prints "Hello, World!" using a custom-built logging framework that logs the message to a file with a timestamp and log level. | codefeedback |
Design an algorithm that determines the greatest common multiple of two numbers in a list of n numbers.
Time complexity requirement: O(n^2)
Space complexity requirement: O(1) | codefeedback |
Write a program that visualizes the given data using a bar chart. The data consists of the name of the month and the corresponding value. The program should display the bar chart with the length of each bar representing the value for that month.
data = [['January', 10], ['February', 15], ['March', 20], ['April', 17]]
... | codefeedback |
Write a SQL query to list the unique office locations which are older than 5 years and have a minimum of 50 employees. | codefeedback |
Modify the given code to handle errors in the following Python script.
```python
num = int(input('Enter a number: '))
try:
print(num * 5)
except ValueError:
print("Invalid input. Please enter a valid number.")
```
# Instructions #
You are required to modify the given code to handle errors in the following Py... | codefeedback |
Suggest an enhancement to the following code to support unicode strings. Additionally, the function should ignore any characters that are not part of the ASCII character set and only replace the specified characters in the string. | codefeedback |
For each tuple in a given list, write a function to get the first element. The function should only return the first element if it is an odd number. If the first element is even, the function should return the second element. The input list will always contain tuples with two integers. Implement the function and test i... | codefeedback |
Write a function to compute the maximum depth of a binary tree from a given list of numbers. However, the list may contain invalid inputs such as strings or negative integers. You need to handle these cases and return an appropriate error message.
For example:
nums = [3,9,20,None,None,15,7,"abc"] should return "Inval... | codefeedback |
Find all prime numbers up to a given number, but also keep track of the number of times each prime number occurs in a separate list. | codefeedback |
Construct an algorithm that checks if the given sequence is an arithmetic sequence. The sequence may contain negative numbers and can have a length of up to 10^6. The algorithm should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Find the nth Fibonacci number in a given range, where the range is defined as the Fibonacci sequence between two given numbers.
For example, given the range [10, 100], the Fibonacci sequence between 10 and 100 is [13, 21, 34, 55, 89]. The nth Fibonacci number in this range would be the nth number in this sequence. | codefeedback |
Swap the first and last items in a given list, but also ensure that the length of the list is greater than 1.
my_list = [3, 4, 8, 11, 5] | codefeedback |
Write a function that creates a new array of a given size by copying the elements of a given array. The new array should only contain unique elements from the original array.
input_list = [1, 2, 3, 2, 4, 5, 1]
size = 4 | codefeedback |
Generate a function that takes the base and height of a regular triangle as parameters and returns the area of the triangle. The function should include the following steps:
1. Prompt the user to enter the base and height of the triangle.
2. Store the values entered by the user in variables.
3. Calculate the area of th... | codefeedback |
Create a function that takes a string representation of a JSON object and converts it into a Python dictionary. The JSON object may contain nested objects, arrays, and primitive data types such as strings, numbers, booleans, and null. The function should handle cases where the JSON object is not well-formed by returnin... | codefeedback |
Calculate the final price of a product after applying a 15% discount and a 10% sales tax.
Price: $100
Please note that this is just one example of how the difficulty can be increased. You can choose to modify the question in any other way that you feel will make it more challenging. | codefeedback |
Construct an HTML page with a navigation bar and three sections. The navigation bar should have dropdown menus with submenus. The first section should contain a form with input fields and a submit button. The second section should display a dynamic table with sorting and filtering functionalities. The third section sho... | codefeedback |
Construct a loop that will print the upside down triangle shape below.
1
12
123
1234
12345 | codefeedback |
Create one line of code to sum the contents in a given array, without using any built-in sum function or list comprehension. Additionally, the solution must have a time complexity of O(n), where n is the length of the array. The input array will only contain positive integers.
my_array = [2, 3, 5, 7, 11] | codefeedback |
Write a function to sort a dictionary of dictionaries in descending order based on a given key. However, the key can be nested within multiple levels of dictionaries and lists.
For example:
d = {'dict1': {'name':'tom','age':20},
'dict2': {'name':'jerry','age':25},
'dict3': {'name':'bill','age':24}}
key = 'ag... | codefeedback |
Construct a one-liner that takes a nested dictionary and reverses the keys and values of the dictionary, where the nested dictionary can have multiple levels of nesting.
my_dict = {'Tony': {'age': 25, 'gender': 'male'}, 'Peter': {'age': 30, 'gender': 'male'}} | codefeedback |
Implement a class method in C++ that takes a string parameter, checks to see if it is all uppercase, and outputs a Boolean value. Additionally, if the input string is empty, the method should throw an exception with the message "Empty string is not allowed". | codefeedback |
Implement a quicksort algorithm in Python to sort a list of 6 integers [52,85,23,6,37,77].
You must use a recursive approach and cannot use any built-in sorting functions or libraries. Additionally, the sorting algorithm must be implemented as a separate function rather than using the built-in sort() method of Python ... | codefeedback |
Write a JavaScript function that checks if a given parameter is a leap year. Additionally, the function should return the number of leap years between the given parameter and the current year. | codefeedback |
Create a program that takes a positive integer n as input and prints the pattern given below. The program should validate the input to ensure that n is between 1 and 10 (inclusive). If the input is invalid, the program should display an error message and ask for a valid input. The pattern should be printed in a clockwi... | codefeedback |
Compute the square root of the sum of the first 150 prime numbers using C++. | codefeedback |
Generate a random 4x4 array using Java. The array should contain only unique numbers ranging from 1 to 16. | codefeedback |
Write a function to search in a 1D array of integers, and return the index of the target if it is present. The target must be found using a binary search algorithm.
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
target = 8 | codefeedback |
Write a function to return the count of all prime numbers from 1 to n (inclusive) where n is a positive integer greater than or equal to 2. | codefeedback |
Implement the Shell sort algorithm in Python.
Note: You are not allowed to use any built-in sorting functions or libraries for this implementation. | codefeedback |
Suggest a way of converting the given JSON object into CSV format, while also ensuring that the output CSV file is sorted in ascending order based on the "Age" field. | codefeedback |
You need to code a function in JavaScript that takes in a string and checks if the length of the string is greater than 10 characters and contains at least one uppercase letter, one lowercase letter, and one special character. | codefeedback |
Create a SQL query to find the employees with the highest salary in each job role, but exclude any employees who have been employed for less than 5 years. | codefeedback |
Create a query in SQL to list all the employees with their salary, who work in the IT department and have more than 10 years of experience. Additionally, display the average salary for employees in the IT department and the maximum salary among those with more than 10 years of experience. | codefeedback |
Develop an SQL query to find the name and email address of the employees who do not have any job role and have been employed for more than 2 years. | codefeedback |
Write a Java program to ask the user to enter a number and then find and print the corresponding Lucas number. | codefeedback |
Develop an algorithm in C++ to reverse a linked list, but with the following additional requirements:
1. The algorithm should have a time complexity of O(n), where n is the number of nodes in the linked list.
2. The algorithm should use only a constant amount of additional space, i.e., the space complexity should be ... | codefeedback |
Create a Swift program to remove duplicates from a given array, but without using any additional data structures. The program should have a time complexity of O(n^2), where n is the size of the array. | codefeedback |
What is a function pointer and how can it be used in C programming? Provide an example of a function pointer declaration and usage in a program. | codefeedback |
Increase the difficulty by adding more reasoning steps and modifying the code to improve efficiency:
Debug the following code in Java to list all the prime numbers until 1000.
class Main {
public static void main(String[] args) {
for(int i = 2; i < 1000; i++) {
if (isPrime(i)) {
... | codefeedback |
What are the three main pillars of Object-Oriented Programming and briefly explain each one? | codefeedback |
Create a database in SQL named "Contacts" that consists of two tables: "Person" and "Address". The "Person" table should have columns for "First Name", "Last Name", "Phone Number", and "Email Address". The "Address" table should have columns for "Street", "City", "State", "Zip Code", and "Country". Implement referentia... | codefeedback |
Structure an HTML form taking inputs of name, age, email address, and phone number. Additionally, implement form validation to ensure that all fields are filled out correctly before submitting the form. Include error messages that are displayed if any of the fields are left empty or contain invalid data. Use appropriat... | codefeedback |
What are the benefits and limitations of Polymorphism in Object-Oriented Programming? | codefeedback |
Write a SQL query to find the most recent 5 login dates for each user who has logged in at least 10 times in the last month.
table_name: users
column_names: user_id, login_date | codefeedback |
Reverse the words in a given sentence using JAVA.
String sentence = "Hello World"; | codefeedback |
Explain how binary search works and provide a step-by-step algorithm to implement it. Additionally, discuss the time and space complexity of binary search and provide examples of scenarios where it is efficient and inefficient. | codefeedback |
Generate the fibonacci sequence for the first 10 numbers using PHP. The solution should be implemented using recursion and without using any loop constructs. | codefeedback |
Construct a for loop that prints the square of each number from 1 to 10 and also prints an asterisk after each square. Additionally, the program should skip any number that is divisible by 3 and only print the squares and asterisks for the remaining numbers. | codefeedback |
Create an HTML page that includes a dynamically generated chart using data fetched from an API. The chart should display real-time updates every 5 seconds. Additionally, implement a feature that allows the user to filter the chart data based on specific criteria. | codefeedback |
Compare two strings and remove all letters from the first string which are present in the second string and vice versa, while also keeping track of the frequency of each letter that is removed. Finally, return the letters that were removed along with their frequencies in a sorted order.
string1 = "Hello World!"
string2... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.