instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a class in Ruby that implements the following methods: `add`, `subtract`, `multiply`, and `divide`. The class should handle both integer and floating-point numbers, and should round the result to the nearest whole number when using the `divide` method. The class should also keep track of the total number of opera... | codefeedback |
Create a function in Python to find all pairs of distinct integers from two given lists that sum up to k, where the absolute difference between the integers in each pair should be greater than or equal to a given threshold value. | codefeedback |
Create an API in Go that takes a string and returns the amount of words present in the given string. However, the API should also be able to handle large strings with millions of words efficiently. Ensure that the solution can handle strings with a maximum length of 1 GB and has a time complexity of O(n) and a space co... | codefeedback |
Create a sorting algorithm to order a given array of integers in ascending order, without using any built-in sorting functions or libraries. The algorithm should have a time complexity of O(n^2) and should be implemented using a variation of the bubble sort algorithm. Additionally, the algorithm should be able to handl... | codefeedback |
Design an algorithm in Python to retrieve all elements in a given array that occur only once. Your algorithm should have a time complexity of O(n) where n is the number of elements in the array.
# Additional Information #
- The given array can contain both positive and negative integers.
- The elements in the array ca... | codefeedback |
Write a query to retrieve the names of customers from the Customers table who have placed at least 5 orders in the Orders table. | codefeedback |
Write a C++ program that reads in a series of integers and prints out the most frequent, but with the following additional constraints:
1. The program should handle negative integers as well.
2. The program should handle floating-point numbers as well.
3. The program should handle both single digits and multiple digit... | codefeedback |
Create a dynamic and responsive UI in HTML/CSS for a shopping cart website that allows users to add, remove, and update items in the cart. Implement a search feature that filters products based on user input. Additionally, display the total price of all items in the cart and allow users to apply discount codes for furt... | codefeedback |
Write a JavaScript program to deep clone a given object, including all nested objects and arrays. | codefeedback |
Write a function which takes in a list containing integers, strings, floats, and nested lists, and returns the sum of all numbers in the list, including the numbers in the nested lists.
Example Input: [2, 'John', 8.2, 3.4, [11, 5.6]]
Example Output: 30.2
To solve this problem, the function needs to iterate through ea... | codefeedback |
Create a GUI that displays a dynamically changing text and multiple buttons, where each button triggers a different action when clicked. Additionally, implement error handling to gracefully handle any unexpected user inputs or program failures. | codefeedback |
Write a Python function to generate a list of Fibonacci numbers up to the given limit n, where the time complexity of the function should be O(n). | codefeedback |
Write a Java program to print out the lyrics of the song "Mary Had a Little Lamb", ensuring that each line of the lyrics is reversed before being printed out. Additionally, the program should capitalize the first letter of each word in the reversed line. | codefeedback |
How would you design the data structure to store and process results from a 5-choice multiple choice test, where each question can have multiple correct answers and there is a time limit of 30 seconds for answering each question? | codefeedback |
Given a list of positive integers, write a program to find three elements whose sum equals a given target value. Additionally, the program should return all possible combinations of these three elements.
For example, given the list [1, 2, 3, 4, 5] and the target value of 6, the program should return the following comb... | codefeedback |
You need to write a function to check if the given input is a palindrome string. The function should ignore any punctuation marks and spaces in the string. The function should also be case-insensitive, meaning that "Level" should be considered a palindrome. | codefeedback |
Design a data structure in Java to store student records which includes Roll Number (must be a positive integer), Name (must be a non-empty string), Grade (must be a character from A to F) and a unique Student ID (must be an alphanumeric string of length 10 characters). | codefeedback |
Implement a Class in Java that creates a new array of integers with a dynamic size determined by the user and allows the user to set and get the values of the array. Additionally, the Class should include a method to calculate the sum of all the elements in the array and a method to find the maximum value in the array. | codefeedback |
Construct a for loop in JavaScript to iterate through an array of strings and print out each one. Additionally, each string should be printed out in reverse order. | codefeedback |
Create a program to find the largest common factor in two numbers within a given range.
The program should take three inputs: the two numbers (N1 and N2), and the range (R).
The program should find the largest common factor of N1 and N2 that is within the range of 1 to R.
If there is no common factor within the range, ... | codefeedback |
create a function to compare two strings and return a boolean depending on their equality or inequality. However, you cannot use any built-in string comparison methods or operators such as '=='. Instead, you must implement your own algorithm to compare the strings character by character. The function should return True... | codefeedback |
Create a Java program that implements an AVL tree, which is a self-balancing binary search tree. The program should include methods for inserting a new node, deleting a node, and searching for a specific value. Additionally, the program should provide a method to perform a level order traversal of the AVL tree. | codefeedback |
Write a program to generate the Fibonacci sequence up to a given number n. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. For example, the sequence up to 10 would be: 0, 1, 1, 2, 3, 5, 8. | codefeedback |
Write a function that will format a given string in proper title case. The string may contain multiple sentences and punctuation marks. The function should correctly capitalize the first letter of each word in the string, except for certain words that should be lowercase (e.g., articles, prepositions, conjunctions). Th... | codefeedback |
Write a Python program to analyze the sentiment of a given text.
The program should take as input a list of text sentences and return a sentiment score for each sentence. The sentiment score should range from -1 to 1, where -1 indicates a negative sentiment, 0 indicates a neutral sentiment, and 1 indicates a positive ... | codefeedback |
Create a function that will validate if a given date is in the correct format and also checks if the date is a valid date in the Gregorian calendar.
date = '12/04/2021'
# Additional requirements #
1. The function should return a boolean value indicating whether the date is valid or not.
2. The function should handle l... | codefeedback |
Describe the data structures used to implement a stack data structure and explain how to implement a method that retrieves the minimum element in constant time complexity. | codefeedback |
Describe the step-by-step process of debugging a complex code that involves multiple modules and libraries, where you must identify and fix logical errors, memory leaks, and race conditions, while adhering to strict performance requirements and minimizing downtime during the debugging process. | codefeedback |
Write a C# program that connects to a PostgreSQL database, retrieves data from multiple tables using a join operation, applies sorting and filtering conditions on the retrieved data, and then displays the results in a console application. | codefeedback |
Design a network for sending data from a server to multiple clients simultaneously. Additionally, ensure that the network is secure by implementing encryption and authentication mechanisms. | codefeedback |
In Python, write a script that prints out the elements of a list in reverse order, without using the built-in reverse function or any additional data structures. The list should be modified in-place. The time complexity of the algorithm should be O(n), where n is the length of the list. | codefeedback |
Write a program that takes a URL as input and extracts all the links present on the webpage. The program should then display the number of internal links (links pointing to the same domain) and external links (links pointing to other domains). | codefeedback |
Write a SQL statement to select the names, IDs, and addresses of customers from the customers table that live in California and have made at least 3 purchases in the past month. | codefeedback |
Write a line of C code to declare a 2D array of size 5x5 and initialize each element of the array with a unique prime number. | codefeedback |
Implement a functional programming paradigm in Python that includes the following features:
1. Higher-order functions: Create at least three higher-order functions that take in other functions as arguments or return functions as results.
2. Pure functions: Implement at least five pure functions that do not have any s... | codefeedback |
Given a string of integers, create a method to generate an array in which each integer is added to the sum of its neighbors. However, the sum of the neighbors should only include integers that are divisible by 2. The resulting array should be sorted in ascending order.
s = "3456978" | codefeedback |
Calculate the sum of the cube of even numbers from 1 to n, where n is a positive integer. | codefeedback |
Write a PHP script that creates a MySQL database table with three fields: "ID" (auto-increment), "name" (unique and alphanumeric), and "age" (between 18 and 100 inclusive). The script should also check if the table already exists before creating it, and handle any potential errors or exceptions that may occur during th... | codefeedback |
Write a program to convert a given 2D matrix into a 1D array. Your program should handle error cases where the input matrix is not a valid 2D matrix.
matrix = [[1,2,3],[4,5,6]]
Output: [1, 2, 3, 4, 5, 6]
matrix = [[1,2,3],[4,5,6],[7,8]]
Output: Invalid matrix. Rows have different lengths.
matrix = [[1,2,3],[4,5],[6,... | codefeedback |
Implement a JavaScript function to print all the leap years between 1900 and 2100 that are divisible by both 4 and 400 but not divisible by 100. | codefeedback |
Given a string and an int n, write a function to extract all possible subsequences of length n from the string. The function should return a list of all the subsequences.
s = "hello world", n = 6 | codefeedback |
Re-implement the Fibonacci sequence in Python. The function should take an integer `n` as input and return the `n`th number in the Fibonacci sequence.
The Fibonacci sequence is defined as follows:
- The 0th number is 0.
- The 1st number is 1.
- Each subsequent number is the sum of the two preceding numbers.
The funct... | codefeedback |
Write a JavaScript function to check if a number is in the Fibonacci sequence. Additionally, handle edge cases where the input number is negative or zero by returning an appropriate error message. | codefeedback |
Given a dataframe with integers, write a function that adds a new column that contains the results of a calculation between two columns, where the calculation is performed only if the value in column A is greater than the value in column B. If the calculation cannot be performed, insert a null value in the new column. ... | codefeedback |
Why is it important to understand and analyze the algorithmic complexity of a solution? Provide a brief explanation and discuss its relevance in the context of developing efficient software applications. | codefeedback |
Given a data table, write a function to select the columns. The function should also allow the user to specify a condition to filter the rows based on a given column and value. The selected columns should be returned as a new data table. The function should handle the case where the specified column does not exist in t... | codefeedback |
Define a function that takes a string as input and returns true if it is a valid IPv6 address.
ip_str = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
Note: IPv6 addresses are represented as eight groups of four hexadecimal digits, separated by colons. Each group can be abbreviated by using double colons (::), but there c... | codefeedback |
Design a GUI app to welcome the user and output a message. Additionally, implement a functionality that allows the user to input their name and display a personalized welcome message. | codefeedback |
Deduce whether the following code is a valid Java statement:
Create a Java program that prompts the user to enter a number and assigns that number to a variable named "num". Print whether the entered value is odd or even. | codefeedback |
Retrieve data from a collection in a MongoDB database, where each document contains multiple nested fields, and display the result in ascending order based on a specific field. The nested fields must be accessed and compared during the sorting process.
db.myCollection.find().sort({ "field1.field2.field3": 1 }) | codefeedback |
Given a string, write a code that checks it for palindrome in O(1) space complexity and O(n) time complexity.
str = "abba" | codefeedback |
Create a class that implements a polygon using an array of Point objects. The polygon should support the following operations:
1. Calculate the perimeter of the polygon.
2. Calculate the area of the polygon.
3. Check if a given point lies inside the polygon.
4. Check if a given point lies on the boundary of the polygo... | codefeedback |
Print out the sum of even numbers from the following range, where each even number should be squared before adding to the sum. The program should also exclude the number 4 from the calculation.
range(1,10) | codefeedback |
Write a function to get data from a NoSQL database and perform a specific operation on the retrieved data.
// Database Name: MyDatabase
// Collection Name: userData
// Search Query: username: 'admin'
// Fields to Return: firstName, lastName
// Operation: Concatenate the first name and last name and return the result as... | codefeedback |
Write a Python code to find the largest and the second largest numbers in a list. The list can contain duplicates and can have a length of up to 10^6 elements. The code should have a time complexity of O(n) and should not use any built-in sorting functions or libraries. List: [2, 9, 12, 45, 10, 20, 45, 12, 9, 2] | codefeedback |
Implement a function that takes in two integers and returns their bitwise AND, OR, and XOR results. The function should return a list containing the three results in the following order: AND, OR, XOR. | codefeedback |
Write a function that reverses a string in place without using any additional data structures. The function should have a time complexity of O(n) and a space complexity of O(1).
Example:
Input: "Hello world"
Output: "dlrow olleH" | codefeedback |
Generate a program in Java to find the mean and median of n numbers. The program should have a time complexity of O(nlogn) and a space complexity of O(n). | codefeedback |
Create a RESTful API endpoint that fetches user details from an external API and stores them in a relational database. The endpoint should only be accessible by authenticated users with the role of "admin". The API call should include the username and password as parameters, and the user details should be validated and... | codefeedback |
Report the number of unique words in the following text, excluding any words that contain the letter 'a' and have more than 5 characters.
This is a sample text | codefeedback |
Create a one line solution in Python to remove all vowels from a string, but the solution should not use any built-in string manipulation functions or methods such as replace() or translate(). | codefeedback |
Write a regular expression that matches all prime numbers within a given string. | codefeedback |
Create a regular expression to check if a given string contains any the letter 'X'. Additionally, the regular expression should only match the letter 'X' when it is not followed immediately by the letter 'Y'. | codefeedback |
Find the length of the longest common subsequence in the following two strings, considering that a subsequence is defined as a sequence that is obtained by deleting some elements from the original sequence, but maintaining the order of the remaining elements: "ABCBDAB" and "BDCABA". | codefeedback |
Create a function in Python to return the approximate value of sin(x) using degrees, without using the math module or any built-in trigonometric functions. | codefeedback |
What is the result of x = 2 and y = 3 in this function, f(x,y) = x^3 + 2y^3 + y^2? | codefeedback |
Generate a list of all the prime numbers in the range from 0 to the given number n, but exclude any prime numbers that contain the digit 5. | codefeedback |
Create a function to normalize a given pandas dataframe by scaling all values between 0 and 1, while also rounding the values to the nearest two decimal places. | codefeedback |
Explain the concept of memory leak in C++ and provide an example code that demonstrates a memory leak situation. | codefeedback |
Create an array of 15 random floats in Python between 0 and 1, ensuring that the sum of all the floats in the array is greater than 10 and the average is less than 0.5. | codefeedback |
Write a SQL query to find the name and address of a customer from a given customer id. The address should be in a specific format: [street], [city], [state], [country]. Additionally, the query should only return customers who have made at least 3 purchases. Consider the following schema for the tables:
Table: customer... | codefeedback |
Write a PHP function to describe a variable type given the value, with the additional requirement that the function should return "String" if the value is a string and has a length greater than 5 characters, otherwise it should return "Short string". | codefeedback |
Make an API call to retrieve the latest news headlines for the world, but exclude any headlines containing specific keywords such as "politics", "entertainment", or "sports". | codefeedback |
Remove all HTML tags from a string, but also remove any content inside the tags. Additionally, convert all HTML entities to their corresponding characters.
Input: "<h1>Hello & <strong>World</strong></h1>"
Expected Output: "Hello & World" | codefeedback |
Find the third smallest element in an array of distinct positive integers, where the array size is greater than or equal to 5. | codefeedback |
Configure the following network parameters while also validating the input:
1. The IP address must be in the format "x.x.x.x" where x is a number from 0 to 255.
2. The netmask must be in the format "x.x.x.x" where x is a number from 0 to 255.
3. The default gateway must be in the format "x.x.x.x" where x is a number fr... | codefeedback |
Print all possible combination and permutations with length 4 for a given array.
[1, 2, 3, 4]
In addition to printing all possible combinations and permutations, also calculate the sum of each combination and permutation and print the combinations and permutations in descending order based on their sums.
Furthermore,... | codefeedback |
Design a function in Java to output the same string in reverse order, while also converting all uppercase letters to lowercase and vice versa. String: 'Hello World!' | codefeedback |
Write a Python code to calculate the number of unique combinations of three digits from 0 to 9, where the sum of the three digits is equal to 15. | codefeedback |
Write a query in SQL to show all the details of the customers with age greater than 30 and their total purchase amount.
Table name: customers
Fields: name, age
#Additional Requirements#
1. Calculate the total purchase amount for each customer and display it as a separate column.
2. Sort the result in descending order ... | codefeedback |
Calculate the amount of UTF-8 bytes needed to code a string "Hello" considering that the string can contain up to 100 characters and must be converted into UTF-8 using a recursive approach. | codefeedback |
Implement a custom promise-based JavaScript library that includes the following additional functionalities:
1. Implement a method that allows chaining multiple promises together.
2. Implement a method that allows parallel execution of multiple promises and returns the combined result.
3. Implement a method that allows... | codefeedback |
Generate a code in Python to generate a list containing multiplication table up to a given number N. The code should be able to handle large values of N efficiently. | codefeedback |
Convert a doubly linked list to an array in JavaScript.
function LinkedList() {
this.head = null;
this.tail = null;
}
function Node(value, next, prev) {
this.value = value;
this.next = next;
this.prev = prev;
}
let list = new LinkedList();
list.head = new Node(1, new Node(2, new Node(3, new Nod... | codefeedback |
Write a function in Java that returns a random element from an array. However, the random element should not be equal to the previously returned element.
int[] A = {3, 5, 7, 9, 12}; | codefeedback |
Describe the Pandas feature "DataFrame" and provide an example of how it can be used in data analysis.
#Additional Instructions#
Explain the differences between a DataFrame and a Series in Pandas and describe when it is appropriate to use each one. | codefeedback |
Create a SQL query that returns the average number of orders per month for customers in California, where the orders should only include those that were placed in the last 6 months. | codefeedback |
Organize the given code snippet into an array data structure, but ensure that all strings starting with a vowel are placed at the beginning of the array, followed by the remaining strings.
Example input: ["1", "Hello", "there", "10", "45", "Apple"]
Example output: ["Hello", "there", "Apple", "1", "10", "45"] | codefeedback |
Describe the feature of "promise" in JavaScript and implement a function that demonstrates the chaining of multiple promises. The function should accept an array of URLs and make HTTP requests to each URL sequentially using promises. The function should resolve with an array of the responses received from each request ... | codefeedback |
Develop a Python code that takes a string as input, removes any punctuation marks and numbers from the string, and converts it to all uppercase. The code should also count the number of vowels in the resulting string and print the frequency of each vowel. Additionally, the code should keep track of the total number of ... | codefeedback |
Calling a calculator API, what is the output of the query "3 * (9 + 5) / 8"?
**Note:** The API returns the result as a string.
**Sample Input:** "3 * (9 + 5) / 8"
**Sample Output:** "4.5" | codefeedback |
Write a MySQL query to get the sum of all values for a certain field in a particular table, but only for students whose age is greater than 18. | codefeedback |
Write a function that takes an array of integer values as input and returns the average of all the values.
The function should perform the following steps:
1. Check if the input array is empty. If it is, return 0 as the average.
2. Check if the input array contains only integer values. If it doesn't, raise a ValueErro... | codefeedback |
Use the requests library to write a Python program that sends an HTTP GET request and parses the response to extract specific data.
url = "http://example.com"
Write a function called "get_specific_data" that takes in the URL as a parameter and returns a list of specific data points extracted from the response. The sp... | codefeedback |
Write a SQL query to select all entries in a given table with a value larger than 100 and the entries must be sorted in descending order of the values. | codefeedback |
Write a piece of code to store 5 values in a single variable, where each value represents a different data type. | codefeedback |
Create a class in Java that represents books in a library. Each book should have a title, author, genre, publication year, and availability status. The availability status should be represented by a boolean value indicating whether the book is currently available for borrowing. Additionally, the class should include me... | codefeedback |
Change the following piece of Java code to make sure that the parameter passed is a valid date in the format "dd/mm/yyyy" and that it falls within a specified range of dates from January 1st, 1900 to December 31st, 2100.
public boolean isValidDate(String date){
// return true if date is valid
} | codefeedback |
Write a SQL query to find all the entries in a given table that contain a specific "value" in the given column. The query should also sort the results in descending order based on another column and limit the number of results to 10. | codefeedback |
Write a HTML and CSS code that creates a 4x4 grid. Each grid cell should have a different background color. The grid should also have a border and each cell should have a unique ID. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.