instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Design a C++ program to read and display a matrix of integers. The matrix should be dynamically allocated using the `new` operator and deallocated using the `delete` operator. The program should also provide functionality to perform the following operations on the matrix:
1. Find the sum of all the elements in the mat... | codefeedback |
Write a program that simulates a sorting algorithm to sort a large array of integers in ascending order. The program should have a time complexity of O(n log n) or better.
In addition to sorting the array, the program should also display the sorted array in a table format on a webpage. The table should have multiple c... | codefeedback |
Create a React component that displays the text "Hello World!" in a red font color, with a font size of 20 pixels, and centered horizontally and vertically in the middle of the screen. Additionally, the text should fade in and out continuously, transitioning smoothly between opacity values of 0 and 1. | codefeedback |
Write the code for the following sorting algorithm, Comb Sort.
Comb Sort is an advanced variation of the Bubble Sort algorithm. It works by repeatedly swapping adjacent elements if they are in the wrong order, with a decreasing gap size. The gap size starts with the total number of elements in the list and decreases b... | codefeedback |
Write an HTML code snippet for creating a search box that includes the following features:
1. Add a placeholder text inside the search box that says "Enter your search query".
2. Add a submit button next to the search box labeled "Search".
3. Validate the search box input so that it cannot be submitted if it is empty.... | codefeedback |
Generate a Fibonacci sequence up until the nth term, where n is given as an input and is between 1 and 1000. Write a function that calculates the sum of all the even-valued terms in the sequence. | codefeedback |
Write a Java program for computing the product of two matrixes, where each matrix is represented as a two-dimensional array.
The program should take input for the dimensions of the two matrixes and check if matrix multiplication is possible. If the multiplication is possible, the program should then take input for the... | codefeedback |
Initialize a 2D array with all elements set to a specific value in C, but now the time complexity should be O(n^2) and the space complexity should be O(1). | codefeedback |
Take the input list and transform it to a dictionary where the keys are the elements of the list and the values equal to the sum of their ASCII values. Make sure to handle any exceptions that may occur during the process.
my_list = ["apple", "banana", "strawberry"] | codefeedback |
Suggest an efficient algorithm to search for a target element in a sorted array using Java. The time complexity of your algorithm should be better than O(log n), where n is the size of the array. Additionally, the algorithm should handle duplicate elements in the array efficiently and return the first occurrence of the... | codefeedback |
Change the code so that it swaps the contents of two variables without using a temporary variable or any built-in swapping functions, and also without using any arithmetic operations.
a = "Hello"
b = "World" | codefeedback |
Output the product of all the elements in the two-dimensional array, but only consider the elements whose values are perfect squares.
arr = [[1, 4, 9], [16, 25, 36], [49, 64, 81]] | codefeedback |
Write a JavaScript function that takes in a string as input and returns the number of unique characters in the string. Your function should be case-sensitive, meaning that 'a' and 'A' should be considered different characters. Your function should ignore any non-alphabetic characters in the string. The time complexity ... | codefeedback |
Increase the difficulty by requiring the removal of all occurrences of "abcd" and "efgh" in a case-insensitive manner.
string s = "abcd ABcd abcd abcd efgh efgh EFgh EFgh"; | codefeedback |
Create a function that takes two strings as inputs and outputs their concatenation, but with the condition that the resulting string should only contain unique characters. Additionally, the function should return the resulting string sorted in ascending order.
Constraints:
- The length of each input string will not ex... | codefeedback |
What is the name of the following component of a computer system:
A component that can perform complex data processing and calculations, involving multiple logical steps and decision-making, and is specifically designed for processing large volumes of real-time financial data in a high-frequency trading environment. | codefeedback |
Convert the given JavaScript function to TypeScript and implement it as a class method with the following additional requirements:
1. The class must be named "OccurrenceCounter".
2. The class must have a constructor that takes an array of numbers as a parameter and assigns it to an instance variable named "numList".
3.... | codefeedback |
Generate a valid MySQL query to retrieve a column from a table where the column is a concatenation of three other columns from the same table, with a condition that only rows where the concatenated column starts with a specific letter and ends with another specific letter are returned. Additionally, the query should re... | codefeedback |
Suggest a plugin or software that can be used to debug a complex React application that involves server-side rendering and Redux state management, and explain the key features and advantages it offers for debugging purposes. Additionally, provide a step-by-step guide on how to use the suggested tool to effectively debu... | codefeedback |
Generate a correct JavaScript program to convert a string into an array, ensuring that all characters are converted to their corresponding ASCII values. The program should also handle special characters and non-English characters. Additionally, the program should be optimized to have a time complexity of O(n) and a spa... | codefeedback |
What type of function is needed to solve the following problem
Compute the sum of the squares of all prime numbers in a given list of numbers, excluding any numbers that are divisible by 3 and 5 simultaneously. | codefeedback |
Using the comment as a guide, edit the code that prints "X out of 10" to print "X out of Y", where Y is a random integer between 1 and 1000. The value of X must be between 1 and Y, inclusive. | codefeedback |
Write a python code to calculate the area of a triangle given the coordinates of its three vertices: A(x1, y1), B(x2, y2), and C(x3, y3).
In addition, please implement the following:
1. Validate that the given coordinates form a valid triangle. This means checking if the three points are not collinear.
2. Handle the ... | codefeedback |
Create a function in Python that adds two numbers, but the numbers must be positive prime integers less than 1000. | codefeedback |
Generate an XOR function in C++ that takes in two integer arguments and returns the XOR result. Additionally, the function should handle cases where one or both of the input arguments are not valid integers and throw an exception. The time complexity of the function should be O(1) and the space complexity should be O(1... | codefeedback |
Using the given input, modify the following HTML code so it shows a list of 10 items with each item having a different color. The colors must be randomly generated hexadecimal values and should not be repeated. Each color should have at least one digit in its value.
To ensure that the colors are distinct, you can crea... | codefeedback |
Please cut and paste the following Java code snippet and add a condition to ensure that the number entered is always a prime number. Additionally, modify the code to handle any exceptions that may be thrown during input.
```java
import java.util.InputMismatchException;
import java.util.Scanner;
public class Main {
... | codefeedback |
Use a while loop to print the message "Hello!" a random number of times between 50 and 100 (inclusive). | codefeedback |
Calculate how many distinct values can be inserted in a balanced binary tree containing N nodes, where N is a positive integer. The values must be inserted in such a way that the resulting tree remains balanced at all times. | codefeedback |
Generate a function in Java for finding the largest prime number in an array of positive integers. The function should handle arrays with a length of up to 1 million elements efficiently. | codefeedback |
Write a Java program to sort the elements of an int array in descending order without using any built-in sorting functions or external libraries. The time complexity should be O(n^2) or lower. The array may contain duplicate elements and its length can be up to 10^6. Additionally, you are not allowed to use any additio... | codefeedback |
Implement Binary Search Tree in Python
You are given a sorted list of integers. Implement a class `BinarySearchTree` that represents a binary search tree. The class should have the following methods:
- `__init__(self)`: Initializes an empty binary search tree.
- `insert(self, value)`: Inserts a new node with the give... | codefeedback |
Write a Swift code to print out the signature of a function that takes two parameters, both of type Int, and returns an Int. The function should have the following requirements:
1. The sum of the two parameters must be greater than or equal to 10.
2. If the first parameter is odd, the function should return the produc... | codefeedback |
Write an SQL query to select the students who scored higher than the average in Maths, have a minimum of 3 years of experience in programming, and are enrolled in a course with a minimum duration of 6 months. | codefeedback |
Create an HTML page that displays a list of users and their ages. The list should be displayed in a table format, with each user's name and age in separate columns. Additionally, include a header row at the top of the table with the labels "Name" and "Age" to clearly indicate the content of each column. Use CSS to styl... | codefeedback |
Edit this code snippet to reverse a string in Python without using the built-in reverse function or slicing. The input string may contain spaces and punctuation marks.
def reverse_string(s):
reversed_string = ""
for i in range(len(s)-1, -1, -1):
if s[i].isalpha():
reversed_string += s[i]
... | codefeedback |
Output the result of 2 to the power of 8 in Java using recursion. Your solution should have a time complexity of O(log n) and must not use any built-in exponentiation functions or libraries. | codefeedback |
Output the nth Fibonacci number in JavaScript, where n can be as large as 10^6. Additionally, the solution must have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Create a new table in a database named 'customers' with the specified columns. In addition to creating the table, also define the data types and constraints for each column. Ensure that the column names are unique and that appropriate primary and foreign keys are set up. Additionally, add a timestamp column to track th... | codefeedback |
Write an SQL query to find all the customers who've purchased at least two items in the last month, have a total purchase amount greater than $100, and are not subscribed to any promotional newsletters. | codefeedback |
You are presented with a string which contains a code snippet. Extract the variable types and their respective values from this string. The code snippet may also contain nested objects and arrays. Additionally, you need to handle any potential errors or exceptions that may occur during the extraction process. | codefeedback |
Translate the following SQL query into MongoDB syntax.
SELECT * FROM properties WHERE bedrooms > 3 and price < 500 and (bathrooms > 2 or garage = true) and city = "New York" and year_built > 2010 and type = "condo" and (pool = true or gym = true) and (balcony = true or patio = true) and (fireplace = true or security_sy... | codefeedback |
Create a function in JavaScript to implement Newton's Method of Numerical Approximation, but ensure that the function can only use a maximum of 10 iterations to approximate the solution. Additionally, add the following requirements:
1. The function should check for convergence after each iteration. If the solution has... | codefeedback |
Create a web server in Java to handle multiple concurrent POST requests with heavy processing and large data payloads. Additionally, implement a custom encryption algorithm to encrypt and decrypt the data payloads before processing them. | codefeedback |
Create a calculator in Python that can handle complex mathematical expressions, including parentheses, exponentiation, and trigonometric functions. Evaluate the following expression and return the result:
(2 * 3)^2 + sin(π/4) - 4 * (6 / 2) | codefeedback |
Write a PHP script to loop through a multidimensional array and print out the values. The script should also calculate and print the total number of elements in the array. Additionally, the script should only print the values that contain at least 5 characters and are in alphabetical order. | codefeedback |
Create a class in jQuery to handle user authentication. The class should have the following functionality:
1. Accept a username and password as input from the user.
2. Validate the username and password by checking if they meet certain criteria. The criteria should include at least 8 characters for the password, a com... | codefeedback |
Write a bash script that searches for a given text string in a directory tree recursively, excluding files with specific extensions and displaying the number of occurrences of the text string in each file. Additionally, the script should also prompt the user to provide a minimum file size, and only search for the text ... | codefeedback |
Identify the type of a variable in a Python program. The program should also check if the variable is a list and return the number of elements in the list. Additionally, the program should handle nested lists and return the total number of elements in all nested lists combined. x = [1, 2, [3, 4, [5, 6], 7], 8, 9] | codefeedback |
Please write a function that takes in two lists as input and returns True if the lists have the same elements in the same order, and False otherwise. The lists can contain any type of elements, including integers, floats, strings, and nested lists. The function should handle all possible types of elements in a consiste... | codefeedback |
Implement a function to return the element that appears most frequently in a list, considering only elements that appear at least twice. The input list will contain at most 10^6 elements, and each element will be an integer between 0 and 10^9. Additionally, you are not allowed to use any built-in sorting or counting fu... | codefeedback |
Create an algorithm in JavaScript to find the closest pair of points from a given set of points. The distance between two points should be calculated using the Euclidean distance formula.
let points = [[2, 0], [4, 4], [-2, 2], [-3, -4], [4, -2]];
To solve this problem, we can follow these steps:
1. Create a helper f... | codefeedback |
Create a loop that will print out all prime numbers between 1000 and 1100, excluding any numbers that are divisible by 5. | codefeedback |
Convert the given list of dictionaries to a tuple of tuples, where each inner tuple contains the name and age of a person. Each person's name must be capitalized and the age must be a positive integer. If a person's name or age is missing or invalid, skip that dictionary.
However, now you also need to sort the resulti... | codefeedback |
Code a solution to remove any element from a given list if it appears more than 10 times.
Example:
Input: [1, 2, 3, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Output: [1, 2, 3, 1, 1, 1, 2, 3, 4, 5, 6... | codefeedback |
Write a program that takes two strings and a separator as inputs and joins the two strings using the separator, ensuring that both strings have at least 5 characters, and output the resulting string. Additionally, the separator should not be a part of either string and the resulting string should be sorted in descendin... | codefeedback |
Create a custom Drupal 8 theme that implements a 3 column layout with a fixed header, a fixed width sidebar, responsive content, and a sticky footer. The header should display a dynamically populated navigation menu that is generated from a custom menu created in the Drupal admin interface. The sidebar should have a co... | codefeedback |
Generate a random 15-element list of integers between -1000 and 1000. Calculate the sum of all the positive numbers in the list, ignoring any negative numbers that are adjacent to a positive number. | codefeedback |
Create a React component that renders a table containing the records from an array of objects. The table should have the following additional features: sorting by name in ascending order, filtering by age greater than or equal to 25, and pagination with 5 records per page. The table should also display the total number... | codefeedback |
Create a program that takes a string as input and returns an object with the count of each unique character in the string, excluding any whitespace characters. The program should also handle cases in a case-insensitive manner.
The program should perform the following steps:
1. Take a string as input from the user.
2. ... | codefeedback |
Convert the following chess board into a 2D array in JavaScript, where each element represents a piece on the board. Each piece is represented by a string of two characters, where the first character represents the color of the piece ('B' for black or 'W' for white) and the second character represents the type of the p... | codefeedback |
Find the lowest positive integer that can not be represented as the sum of exactly three distinct prime numbers. In addition, the sum of the three primes must be the largest possible prime number less than or equal to the given positive integer. | codefeedback |
Run the program located in 'helloworld.py' and ensure that it is able to handle inputs of up to 100 characters in length without any errors or unexpected behavior. Additionally, ensure that the program correctly handles edge cases such as empty input, input containing only whitespace characters, and input containing sp... | codefeedback |
Write a class definition for a Cube class that includes methods to calculate the volume and surface area of the cube, as well as a method to check if the cube is a perfect cube. The Cube class should also have a static variable to keep track of the total number of cubes created and a method to retrieve the total count.... | codefeedback |
Create a SQL statement to select the first ten elements from a table with a specific id and order them in descending order based on their price. The table name is 'products', and the product id is 1. Additionally, the statement should only select products that have a quantity greater than or equal to 5 and their price ... | codefeedback |
## Problem Description
Write a function that takes in an array of integers and moves all the zeros to the end of the array, while maintaining the order of the non-zero elements. The function should return the modified array.
## Example
### Input
[1, 2, 0, 3, 4, 0, 5]
### Output
[1, 2, 3, 4, 5, 0, 0]
## Constraints... | codefeedback |
Develop a program that finds the maximum number of overlapping events within a given time period, taking into consideration that each event has a minimum duration of 3 units of time. Implement a solution that can efficiently handle large input sizes of events, with a time complexity of O(n log n). The program should re... | codefeedback |
Create a new list filled with the same values as the existing list but with the values multiplied by 5. Additionally, the solution should be implemented using a recursive function. The input list may contain up to 10^6 elements and the solution should have a time complexity of O(n), where n is the length of the input l... | codefeedback |
Create a validation rule to check if an email address is valid for an input field in JavaScript. Additionally, ensure that the email address is not a disposable email address (i.e., an email address from a temporary or disposable email service).
To accomplish this, you can follow these steps:
1. Check if the input fie... | codefeedback |
What data structure would be best to store key-value pairs, and why would you choose this data structure over other options? Please provide at least five different reasons for your choice and explain each reason in detail.
Note: You are not allowed to choose the hash table as the data structure for this question. | codefeedback |
Write a SQL query to return all records from the table with a specified column including null values. Additionally, the query should only return records where the age is greater than or equal to 18 and less than or equal to 65. The result should be ordered in descending order by the age column. Table name: my_table Col... | codefeedback |
Formulate a SQL query that fetches the records with the latest date and the highest value in another column called "value". Additionally, order the results in descending order based on the "value" column. Furthermore, filter the results to only include records where the "value" column is greater than the average value ... | codefeedback |
Please write a C++ program that prints the following pattern to the screen:
1
2 4
3 6 9
5 8 11 14
7 10 13 16 19
To solve this problem, you need to modify the given code. | codefeedback |
Write a VBA macro to convert a sequence of text to uppercase, but only for characters that are at odd positions in the sequence. The text is: "Hello World".
You need to implement error handling in your code to handle cases where the input sequence is empty or the sequence contains non-alphabetic characters. If any of ... | codefeedback |
Input a list of numbers and output the maximum and minimum ones in Python. Additionally, calculate and output the average and sum of all the numbers.
Input: [3, 5, 2, 7, 1]
Output:
Maximum: 7
Minimum: 1
Average: 3.6
Sum: 18 | codefeedback |
Write a method to compare two unsorted arrays of integers and find the number of mismatches. The arrays can contain duplicate values. In addition to finding the number of mismatches, the method should also return the indices at which the mismatches occur in both arrays. The method should have a time complexity of O(n) ... | codefeedback |
Design a method for reversing a string in Java without using any built-in string reversal functions or using additional data structures. The method should have a time complexity of O(n), where n is the length of the string. Additionally, you are not allowed to use any additional variables apart from the input string it... | codefeedback |
Implement a class called "Rectangle" that represents a rectangle shape. The class should have private member variables for the length and width of the rectangle.
The class should provide the following public member functions:
1. A constructor that takes two parameters to initialize the length and width of the rectan... | codefeedback |
Create a formula that calculates the total cost of an item given the item price, tax rate, and any applicable discounts or surcharges. Additionally, implement a feature that allows for multiple discount tiers based on the total quantity of items purchased. The discounts should be as follows:
- If the total quantity of... | codefeedback |
Write a Python function to check if a given string is a palindrome and contains all the vowels (a, e, i, o, u) in it in alphabetical order. The string must also not contain any duplicate vowels and must have a length greater than 5 characters. | codefeedback |
Convert a given XML document to a JSON document while maintaining the original hierarchical structure of the XML elements and adding a new constraint that the JSON output should only include specific XML elements that meet certain criteria. Additionally, the solution should handle XML documents with very large sizes (u... | codefeedback |
Write a shell command to switch to a given directory and display the number of files and subdirectories in that directory, recursively counting the files and subdirectories in any nested directories. Additionally, output the total size (in bytes) of all files within the directory and its subdirectories. | codefeedback |
Write a JavaScript function that returns the count of all possible combinations of elements from an array of numbers that sum up to a given target. The function should also return the combinations themselves.
array = [2, 3, 7, 8, 10]
target = 11
For example, given the above array and target, the function should retur... | codefeedback |
Compute the average age of the following ages: 18, 20, 17, 19, 15. The ages must be read from a file named "ages.txt" and the program should handle any file size. Additionally, the program should handle the scenario where the ages in the file are not in the correct format or contain invalid characters, such as letters ... | codefeedback |
Increase the difficulty of the given programming test question by adding the following requirements:
1. Modify the "printName()" method to capitalize the first letter of each word in the name. For example, if the name is "john doe", the method should print "Name is: John Doe".
2. Add a new method "changeName(String n... | codefeedback |
Write a Python function `same_frequency(num1, num2)` that takes in two integers `num1` and `num2` and determines if they have the same frequency of digits. You are not allowed to convert the numbers to strings or use any built-in functions for counting the frequency of digits.
To solve this problem without converting ... | codefeedback |
Write an SQL query to find the list of products whose price is greater than 50, quantity is less than 10, and belong to a specific category.
#Additional Reasoning Steps#
- Add a condition to filter the products by their category.
- Handle cases where there might be no products that meet the given conditions.
- Include... | codefeedback |
Write a script in JavaScript to iterate over a given array of objects and return all objects with the color green. Additionally, the script should only return objects with the color green that have a shape property of either 'circle' or 'square'. The script should also sort the returned objects in ascending order based... | codefeedback |
Write a code snippet to get the name of the planet which is the fifth planet from the sun. Additionally, handle the case where the input number is greater than the total number of planets in the solar system and display an appropriate error message. The code should also handle the case where the input number is negativ... | codefeedback |
Rewrite an SQL statement to add two new columns, 'size' and 'color', to the existing products table. The 'size' column should only allow values of 'small', 'medium', or 'large' and should have a default value of 'medium'. The 'color' column should only allow values of 'red', 'blue', 'green', or 'yellow' and should have... | codefeedback |
Write code to delete all elements in a given Python list which are NOT integer type and have an even index. If the element is a string, also check if it contains any vowels and delete it if it does. If the element is a float, round it to the nearest integer before checking if it is even. Finally, print the sum of all r... | codefeedback |
Explain the concept of polymorphism in object-oriented programming and provide a practical example of using method overriding to demonstrate dynamic polymorphism. Discuss how dynamic polymorphism improves code reusability and maintainability compared to static polymorphism. Additionally, explain the concept of abstract... | codefeedback |
Write a function that takes a list of tuples as input, where each tuple consists of a color name and its value. The function should create a dictionary where the color names are the keys and the corresponding values are the values in the dictionary. The function should then return this dictionary.
The function should ... | codefeedback |
Create an SQL query to select the name and age of all employees that are younger than 25, have been employed for more than 2 years, and have a salary higher than $50,000.
Table: Employees
Columns: employee_id, name, age, hire_date, salary | codefeedback |
Write a python program to find the sum of all the prime numbers between 2 and 1000 (inclusive). | codefeedback |
Create a python anonymous function that squares an input number, but only if the number is positive, less than 10, and even. If the number is odd, return the negative of the number squared. | codefeedback |
Write a python function to calculate the factorial of a given number, but with the additional requirement that the function must use recursion instead of iteration. | codefeedback |
Suggest a type of join to use to find all customers who have placed an order for more than 5 different products and have not made any returns.
Table: Customers
Columns: customer_id, name
Table: Orders
Columns: order_id, customer_id
Table: OrderItems
Columns: order_item_id, order_id, product_id
Table: Returns
Columns: ... | codefeedback |
Modify the following block of code to set a maximum length of the list. Additionally, ensure that the length of the list cannot exceed the maximum length. Finally, implement a custom sorting algorithm to sort the list in descending order.
max_length = 5
lst = [1, 2, 3, 4, 5, 6]
# Erroneous code to increase misdirecti... | codefeedback |
Sort the list using Quick Sort in descending order. The list may contain duplicate elements.
#Reasoning Steps#
1. Select a pivot element from the list (in this case, we can choose the last element as the pivot).
2. Partition the list into two sublists: one with elements greater than or equal to the pivot and one with ... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.