instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create a Python program that takes two lists as arguments, and returns a list that contains the elements present in both lists. The program should also remove any duplicates from the resulting list.
The program should perform the following steps:
1. Create an empty list called "common_elements" to store the elements t... | codefeedback |
Create a Python script to combine two lists into a dictionary. However, instead of combining the lists based on a common attribute, combine them based on multiple common attributes between the elements of both lists.
For example, given the following two lists:
list1 = [{"id": 1, "name": "John", "age": 25}, {"id": 2,... | codefeedback |
What data structure should we use to solve this problem? We want to store a list of names and their associated addresses, and then look up names quickly. Additionally, we need to ensure that the names are sorted in alphabetical order for efficient searching. However, you are not allowed to use any built-in data structu... | codefeedback |
Write a PHP function that takes a string as input and returns the string with all the alphabetic characters in uppercase. Additionally, remove all duplicate characters from the resulting string and sort the characters in descending order based on their ASCII values.
Constraints:
- The input string will contain only al... | codefeedback |
Construct a program that determines the sign of a given number using a nested conditional statement. The program should handle decimal numbers as well.
Constraints:
- The program should be written in a programming language of your choice.
- The program should not use any built-in functions or libraries for determining... | codefeedback |
Construct an array in Python of size n (where n is a positive integer) and fill it with random integers from 0 to 100. Additionally, the array must have unique elements and be sorted in ascending order. The algorithm should have a time complexity of O(nlogn). | codefeedback |
Create a JavaScript object with a number property and a string property. Add a method to the object that takes in two parameters (a number and a string) and returns the concatenation of the number property and the string property. Additionally, the method should only return the concatenation if the number parameter is ... | codefeedback |
Generate a Ruby program to find the sum of the even-valued terms in the Fibonacci sequence up to the 100th term. | codefeedback |
Create a JavaScript object property with a string value that is encrypted using a custom encryption algorithm. The encryption algorithm should incorporate a random salt value and a key derived from a password. The encrypted string should be stored in the property as a hexadecimal string. The password used for encryptio... | codefeedback |
Given a database with multiple tables, write a SQL query to list the name, column names, and data types of all tables in the database. Additionally, order the list of tables by the number of columns in each table in descending order. Make sure to include only tables that have at least one column of type "integer". | codefeedback |
Create a React component to render a table with data from an API. The API returns an array of objects, each representing a person's information. Each person has the following properties: name (a string), age (a number), and job (a string).
The table should display the following columns: Name, Age, and Job. The data fr... | codefeedback |
Write a SQL query that selects the first name, last name, and the full name (concatenation of first and last name) of all users in a customer table, where the last name must be in uppercase, the full name should only include alphabetic characters, and the first name should have at least two vowels. | codefeedback |
Write a SQL query to display a table with the number of records in each month of a year, but exclude the months with no records from the result. Additionally, display the average number of records per day for each month. | codefeedback |
Write a function in JavaScript to get the first 50 prime numbers.
Reference Erroneous Code:
```javascript
function getPrimes(n) {
var primes = [];
var i = 2;
while (primes.length < n) {
if (i === 2) {
primes.push(i);
i++;
} else if (i % 2 !== 0) {
var isPrime = true;
for (var j... | codefeedback |
Implement a function to delete all elements from a given set in constant time complexity, using only a single loop and without using any built-in functions or data structures. | codefeedback |
Generate a logic for a regex expression to detect a valid email address with the following requirements:
- The email address must start with an alphanumeric character.
- The domain name must contain at least one period.
- The domain name must be at least two characters long.
- The email address must end with a valid to... | codefeedback |
Write a SQL query to output the most common first names among all male customers in the customer table, while also considering the total number of orders each customer has made. Additionally, include the percentage of orders made by each customer in relation to the total number of orders made by all male customers. | codefeedback |
Create a web page with a JavaScript function to search for a product in a product inventory using user input. The user should be able to search for a product by either its name or price.
The web page should display the list of products in a table format, with each row showing the name, price, and quantity of a product... | codefeedback |
Create a responsive web page with a React component to fetch data from a RESTful API and display it in a sortable and searchable table. Implement client-side pagination for the table, with a maximum of 10 rows per page. Add a loading indicator while fetching the data and handle error cases gracefully by displaying an e... | codefeedback |
Write a Java program to read the following text and count the number of unique words in the given sentence. However, the program should ignore any words that are enclosed within quotation marks and consider only distinct words.
For example, if the input sentence is:
This is a "sample" sentence. This is another "sample... | codefeedback |
Given a binary search tree and a target value, write a python function to search for the closest node value to the target. The binary search tree is not guaranteed to be balanced. The time complexity of the solution should be O(log n) on average, where n is the number of nodes in the tree. The space complexity should b... | codefeedback |
Write a JavaScript function that takes in an array of positive integers and a number between 1 and 100 (inclusive) as arguments. The function should return the array sorted in ascending order with the number inserted in the right position. The array should not contain any duplicate elements. Additionally, the function ... | codefeedback |
Create a class in C++ to store the rolling average of a stream of numbers. The class should also provide a method to calculate the standard deviation of the numbers in the stream. Additionally, the class should implement a method to remove outliers from the stream before calculating the rolling average and standard dev... | codefeedback |
Write a code that prints all the possible outcomes of rolling three dice and calculates the sum of each outcome. | codefeedback |
Write a program that removes the extra spaces from a given string and makes the spaces between letters and words consistent. The input string can be of any length and can contain special characters. The final output should be in uppercase.
The program should follow the following steps:
1. Take the input string from th... | codefeedback |
Write a Python function that takes in a sentence and reverses the order of the words, while keeping the order of the characters within each word intact. The function should handle punctuation marks and multiple whitespaces between words appropriately.
However, the function should now have a time complexity of O(n), w... | codefeedback |
Write a Python code to find all the prime numbers below a given number and store them in a list. The code should also determine the sum of the digits of each prime number and only include prime numbers whose digit sum is a prime number itself. Additionally, the code should calculate the product of all prime numbers in ... | codefeedback |
How would you create a CSS style for alternating the background color of table rows, with the following additional conditions:
1. The alternating background colors should start with a different color than the default background color of the table.
2. The alternating background colors should be applied to only a specifi... | codefeedback |
Convert the given for loop code to a functional programming approach. Implement the solution without using any built-in functions or libraries, and ensure that the solution is a pure function. The input list should not be modified, and the result should be stored in a new list named "new_list".
Erroneous code:
```py... | codefeedback |
Rewrite the following code snippet from an object-oriented programming perspective.
class Greeting:
def __init__(self, name):
self.name = name
def find_greeting(self):
if self.name == "Alice":
return "Hi Alice!"
elif self.name == "Bob":
return "Hi Bob!"
... | codefeedback |
#Rewritten Test#
Rewrite this code snippet from a functional programming perspective, with the requirement that the implementation must not use any built-in functions or methods for checking if a number is even.
The input is a list of positive integers. Implement a function called `has_even_sum` that returns True if t... | codefeedback |
Construct an HTML page including a heading, button, paragraph, and a form that collects user input. Upon clicking the button, the user's input should be displayed in a separate paragraph on the page. Additionally, implement a validation mechanism to ensure that the user input is a valid email address before displaying ... | codefeedback |
Write a function to reverse the contents of a stack without using any additional data structures. Additionally, the function should have a time complexity of O(n), where n is the size of the stack. | codefeedback |
Given a 2-dimensional array, where each element is a list of integers, write a function to calculate and print the sum of all elements in the array. The array can have any dimensions, where n is the number of rows and m is the number of columns. Each row may have a different number of columns.
Write a function:
```pyt... | codefeedback |
Generate some sample input that can be used to test the edge cases of the following code snippet.
Write a function called `multiply_two_numbers` that takes in two integer inputs `a` and `b` and returns their product. However, the function should include additional logic to handle the following edge cases:
1. If `a` an... | codefeedback |
Write a JavaScript function that takes in an array and returns an array of objects containing the original array elements and their frequency. The function should also sort the objects in the output array based on the frequency of each element in descending order. Additionally, the function should handle the case where... | codefeedback |
Write a Python program to sort the dictionary by key in descending order and only include keys that start with a vowel. The program should also print the total number of vowels in the dictionary.
myDict = {'a': 1, 'c': 3, 'b': 2, 'e': 4, 'd': 5, 'i': 6}
#Erroneous code reference#
Provide a piece of erroneous code tha... | codefeedback |
Write a C++ code to generate a random number in the range 0 - 1000, but the number generated must be divisible by both 7 and 11. | codefeedback |
Create a Bash script that takes in a single argument and prints it in reverse order, without using any built-in string reversal functions or commands. The script should also check if the argument is a valid file path and, if so, display the contents of the file in reverse order instead of just printing the argument its... | codefeedback |
Create a loop in Python to find the sum of all prime numbers from 1 to 1000. | codefeedback |
Write a JavaScript function that takes in two strings as arguments and returns true if the first string is present in the second string, and false otherwise. The function should be case-sensitive.
Example:
```javascript
function isSubstring(substring, string) {
return string.includes(substring);
}
console.log(isS... | codefeedback |
Write a Java program that takes in two integers as command line arguments and adds them together. The program should then print the sum. Additionally, the program should handle cases where the inputs are not valid integers and should display an error message in such cases. In case of an error, the program should prompt... | codefeedback |
Design a SQL query to find all records from the table "Users" where the user's name is "John" and the user's age is greater than 25, and the user's email domain ends with ".com". | codefeedback |
In C++, write a code snippet to print "Welcome to GeeksforGeeks" 10 times using a for loop, but ensure that each time the phrase is printed, the words "GeeksforGeeks" are printed in reverse order and each word is printed in reverse order as well. | codefeedback |
Write a SQL query to find the customer id, name, and salary of the customers whose salary is in the range 2000-6000, have made at least 5 purchases in the last month, and belong to a specific product category such as electronics or fashion. | codefeedback |
You are working for an e-commerce platform and your task is to create a report that shows the top 10 products that have been sold the most in the last month, excluding any cancelled orders. To achieve this, you need to use the mySQL COUNT function to retrieve the number of unique customers who have made at least 5 purc... | codefeedback |
Design a data structure that can efficiently store unique user IDs and their corresponding usernames. Additionally, the data structure should provide fast lookup and deletion of user IDs. What type of data structure is this?
Provide a piece of erroneous code as a reference to increase misdirection:
```
public class U... | codefeedback |
Write a query in SQLite to select the records which have a price lower than 50, a quantity greater than 10, and the name of the product starts with the letter "A". | codefeedback |
Using the HTML provided, add an ID attribute to the div tag to specify the unique identifier "box1". Additionally, use JavaScript to change the background color of the div tag to red when it is clicked. However, this should only happen if the div tag is clicked twice within a span of 1 second. If the div tag is clicked... | codefeedback |
Write a query in MongoDB to find all documents which have a count greater than 100 and less than 200, the name field starts with the letter "A", and the created_at field is within the last 7 days. | codefeedback |
Write a program to calculate the Fibonacci sequence up to a given number.
Please note that you need to implement the Fibonacci sequence using recursion and memoization in your program. | codefeedback |
Visualize the given dataset using a bar chart in matplotlib. The bars should be color-coded based on the value range they belong to. The labels should be displayed in descending order of their values. Additionally, the chart should have a title, x-axis label, and y-axis label. Use a different color for the bars that ha... | codefeedback |
Edit the given code snippet to generate a table in HTML with four columns and three rows. Each cell in the table should contain a randomly generated number between 1 and 100. Additionally, the table should have alternating row colors, with one row being light gray and the next row being white. The table should also hav... | codefeedback |
Develop a function in Java to print the fibonacci series up to a given number 'n', where 'n' is a positive integer greater than 2. The function should also check if each number in the series is a prime number and print "Prime" next to the number if it is. | codefeedback |
Compose an SQL statement to select the column "name" from the table "students" only where the student's age is greater than or equal to 25 and the student's grade is higher than 90. Additionally, order the results in descending order based on the student's grade. | codefeedback |
Create a function in JavaScript that takes in two arrays of integers and returns an object. The object should contain elements where the two arrays have coinciding elements. Additionally, the function should only consider coinciding elements that are prime numbers.
To increase the difficulty, modify the function to ha... | codefeedback |
Develop a program in Java that prints out the following star pattern. The program should take an input from the user to determine the number of rows in the pattern. The number of rows should be between 5 and 15 (inclusive). If the user enters an invalid input, the program should display an error message and ask for inp... | codefeedback |
Create a function in JavaScript that validates a user input as a valid email address, ensuring that it meets the following additional requirements:
1. The email address must contain at least one uppercase letter.
2. The email address must contain at least one lowercase letter.
3. The email address must contain at least... | codefeedback |
Explain the key differences between object-oriented programming and functional programming paradigms, including their main concepts and advantages. Provide specific examples of how each paradigm can be used in software development. Additionally, include a piece of erroneous code that demonstrates a common mistake made ... | codefeedback |
Develop a function in Java that prints out the squares of all prime even numbers between 1 and 100.
#Reasoning Steps#
1. Create a function named "printPrimeEvenSquares" that takes no parameters and returns nothing.
2. Inside the function, create a loop that iterates from 1 to 100.
3. Check if the current number is eve... | codefeedback |
Construct a switch-case statement in JavaScript to print the day of the week, but with the added requirement that the program should also display a message if the day_index value is invalid (i.e. not within the range of 1-7). Additionally, if the day_index is within the valid range but corresponds to a weekend day (Sat... | codefeedback |
Construct a class in Python named "Person" which stores first name and last name in instance variables. Implement a method called "get_full_name" which returns the full name in the format "Last Name, First Name". The first name and last name should be between 2 and 20 characters long. The class should also have a metho... | codefeedback |
Find the nth prime number, where n is a positive integer greater than 100. Additionally, the program should handle inputs up to 10^9 efficiently. | codefeedback |
Calculate the sales tax given a price and a tax rate, but the tax rate must be rounded to the nearest hundredth decimal place. The price should be a positive integer between 1 and 1000, and the tax rate should be a positive decimal number between 0.01 and 0.1. Additionally, you are required to handle cases where the ta... | codefeedback |
Create a dictionary to store the marks of students in a class, along with their respective subjects.
Johnny scored 85 in Mathematics, 90 in English, and 75 in Science.
Jane scored 95 in Mathematics, 85 in English, and 80 in Science.
Tom scored 75 in Mathematics, 80 in English, and 90 in Science.
Write a program to calc... | codefeedback |
Write a filter function in JavaScript to return elements from an array of strings which start with the letter "a" and end with the letter "t". The function should also ignore case sensitivity, so it should match words starting with "A" or "a" and ending with "T" or "t". Additionally, the function should sort the filter... | codefeedback |
Create a function in Python to take a list of integers as input and return the count of pairs whose sum is divisible by 3. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the input list. Additionally, the function should be able to handle a list with duplicate... | codefeedback |
Create a function in JavaScript that takes in an array of strings and returns a new array with all the elements in reverse order. The function should have a time complexity of O(n), where n is the length of the input array. | codefeedback |
Create a SQL query to get the top 10 salaries from a given table, but exclude any employees who have been with the company for less than 1 year. Additionally, the query should only consider employees who have a job title of "Manager" or "Director" and have a salary above $100,000. | codefeedback |
Write a MySQL query to select all customers who have a birthday in the month of May and have made at least 5 purchases in the last 3 months. | codefeedback |
Write a Python program to convert a string to a list of characters, while ignoring any whitespace characters. The string is "This is a test". Implement the solution without using any built-in string or list methods, such as str.split(), list(), or str.join().
Constraints:
- The program must have a time complexity of O... | codefeedback |
Write a program to estimate the value of pi to ten decimal places using the Monte Carlo method, but with the additional requirement that the program must be implemented using a functional programming language. | codefeedback |
Sort all strings in a list alphabetically, using Python.
Time Complexity: O(nlogn)
Space Complexity: O(n)
["apple", "dog", "cat", "banana"]
In addition to sorting the strings alphabetically, remove any duplicate strings from the list. | codefeedback |
Create a Java class to represent a point in 2D space using two fields, x and y. The x and y values should be restricted to prime numbers between -100 and 100, inclusive. Additionally, the class should have a method to calculate the distance between two points in 2D space, but the distance calculation should only consid... | codefeedback |
Construct the loop in the code to find the maximum element in a non-empty array. The array contains positive integers ranging from 1 to 1000. The length of the array can range from 10 to 1000 elements.
In addition to finding the maximum element, modify the code to also find the minimum element in the array.
After f... | codefeedback |
Given a 2-d array of integers, write a method to flatten the array while removing all duplicate elements. The flattened array should be sorted in ascending order. Additionally, if the 2-d array is empty, the method should return an empty array.
Additional Constraint: Your solution should have a time complexity of O(nlo... | codefeedback |
Write an SQL query to display all columns from the table 'products', sorted in descending order by price, where the price is greater than 1000 and the product is in stock. | codefeedback |
Create a deep learning model using LSTM or GRU cells to predict the next word in a given sentence, taking into account not only the previous words but also the context and meaning of the entire text. Additionally, incorporate the ability to generate coherent and meaningful paragraphs based on the learned patterns from ... | codefeedback |
Given a list of numbers, find the smallest number using Python. The list may contain negative numbers and decimals as well. However, you are not allowed to use any built-in functions or methods in Python, such as min(), sorted(), or sort(), to solve this problem. You must implement your own algorithm to find the smalle... | codefeedback |
Write a query in Redis to get all the keys starting with 'user:' and ending with a numeric value. Additionally, exclude any keys that contain the string 'admin' anywhere in the key name. | codefeedback |
Given an array of integers, write a program to find and print the sum of all the prime numbers in the array. You should use a loop structure to iterate through the array in reverse order and only include prime numbers in the loop body. Remember to output the sum of all the prime numbers found.
const array = [3, 8, 2, ... | codefeedback |
Write a function in C++ to find the sum of all prime numbers between 1 and 100, and then print the prime numbers in descending order. | codefeedback |
Write a function in Java to convert hours to minutes, but the function should also handle the case where the input is a negative number and throw an exception if so. Additionally, the function should also validate that the input is a valid integer and throw an exception if it is not. The function should also round the ... | codefeedback |
Calculate the total surface area of a rectangular prism with length n cm, width m cm, and height k cm, considering that each face of the prism must have a different color and each color must be chosen from a given set of c colors. The values of n, m, k, and c will be within a range of 1 to 1000.
Additionally, the time... | codefeedback |
Write CSS code to create a responsive navigation bar with the following specifications:
1. The background color of the navigation bar should be purple.
2. The navigation bar should be fixed at the top of the page, even when scrolling.
3. The navigation bar should have a height of 50 pixels.
4. The navigation links sho... | codefeedback |
Using C++, create a program to calculate the volume of a rectangular prism given the length, width, and height. However, you are not allowed to use the multiplication operator (*) or any built-in math functions. Additionally, the program should only allow integer inputs and the output should be rounded to the nearest w... | codefeedback |
Write a JavaScript code for the following action: When the user types "I'm hungry!" in the text box and presses the enter key, the system will check if the user has entered a valid number in the adjacent number input field. If the entered number is greater than or equal to 5 and is a prime number, the system will displ... | codefeedback |
Using Java, create a program to compute the area and circumference of a circle given the radius. Implement the following requirements:
1. The program should prompt the user to enter the radius of the circle.
2. Validate the user input to ensure that it is a positive integer.
3. Calculate and display the area of the cir... | codefeedback |
Convert the following time from Central Daylight time to Eastern Standard time: 15:00 on a specific date. Use a different programming language than what you are familiar with to solve this problem. | codefeedback |
Create a function that returns the first non-repeating character in a given string, excluding any whitespace characters.
string = 'This is a sample string'
The function should return 'T' as it is the first character that does not repeat in the string, while disregarding any whitespace characters. | codefeedback |
Create a relational database with the following table structure, ensuring that each table has a primary key and at least two foreign key constraints. Additionally, implement triggers to enforce referential integrity for the foreign key constraints. | codefeedback |
Given a string consisting of lowercase and uppercase letters, spaces, and punctuation marks, parse the string and reverse the order of words, while maintaining the capitalization of the first letter of each word. Additionally, you need to remove all the vowels from the reversed string. The string may contain multiple c... | codefeedback |
Create an array with 10 elements, each element must be a randomly generated positive integer between 1 and 1000 inclusive. The array must be sorted in descending order and must not use any built-in sorting functions or methods. | codefeedback |
Write a code in C# to create a ranking system for 20 players based on their scores.
Player1: 65
Player2: 82
Player3: 47
Player4: 79
Player5: 65
Player6: 74
Player7: 53
Player8: 91
Player9: 63
Player10: 82
Player11: 87
Player12: 77
Player13: 82
Player14: 92
Player15: 58
Player16: 70
Player17: 80
Player18: 82
Player19: 7... | codefeedback |
Find the maximum of the following array and its index. Additionally, remove any duplicate elements from the array before finding the maximum. Handle any errors that may occur during the process.
Example input: [4,1,7,9,3,7,9,2,2,5]
Example output: The maximum element is 9 at index 3. | codefeedback |
Write a multithreaded class in Java to submit a form, ensuring that each form submission is unique and includes a captcha verification. The form must also include a file upload functionality, where the user can upload multiple files simultaneously. | codefeedback |
Using a for loop and an if statement, count how many prime numbers between -100 and 100 are in the given array. The array can contain both positive and negative integers. | codefeedback |
Create a function that takes an integer as input and returns the sum of the squares of all the numbers between 1 and the input number, excluding any multiples of 3. Additionally, exclude any numbers that are perfect squares. | codefeedback |
Write a code that sorts an array in descending order, but do not use any built-in sorting functions or methods. You can only use basic operations such as loops, conditional statements, and variable assignments. The input array will contain integers ranging from -1000 to 1000, and its length will be between 1 and 1000.
... | codefeedback |
Construct a CSS rule to either hide or show the paragraph element with the class "description". Additionally, ensure that the CSS rule only applies to paragraphs within a div element with the class "container". | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.