instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Implement a web scraper in Python to extract all headlines from a web page and store them in a database. Additionally, filter out any duplicate headlines and only store the unique ones in the database. Ensure that the web scraper can handle different HTML structures and is able to extract headlines from web pages with ... | codefeedback |
Given a range of numbers [a, b], write a program to find the sum of all prime numbers within that range. Additionally, your program should also output the product of all prime numbers within the range. | codefeedback |
Write a C++ program that takes a string as input. The program should remove all duplicate characters from the string, sort the remaining characters in descending order, and print the resulting string.
Example:
Input: "abracadabra"
Output: "rdbca"
Additional Requirements:
1. The program should be case-sensitive, so 'A... | codefeedback |
Create a SQL query to compute the average salary of the employees who have been with the company for at least 2 years, whose salary is above $50,000, and whose job title contains the word "Manager". | codefeedback |
Make an API request to fetch the top 10 trending topics from Twitter. Store the data in a list and sort it in descending order based on the number of tweets for each topic. Display only the top 5 trending topics with their corresponding number of tweets. Additionally, exclude any topics that have less than 1000 tweets ... | codefeedback |
Write a SQL query to combine three tables into one and delete the duplicate rows. The resulting table should also include a column indicating from which original table each row came from.
Table A:
id | name | age
1 | John | 20
2 | Mary | 22
3 | Jane | 19
Table B:
id | name | age
4 | Mark | 25
5 | John | 20
6 | Jack | ... | codefeedback |
Write a SQL query to find the first name and last name of all students enrolled in courses "CSCI-203" and "MATH-301" whose student ID is greater than 100, whose GPA is above 3.5, and who have taken at least 3 courses in total. | codefeedback |
Write a SQL query to calculate the standard deviation of student grades for each subject from the following table. Also, include the average grade for each subject in the result.
Table: Grades
Columns: Student (text), Subject (text), Grade (integer)
Original Data:
Student | Subject | Grade
John | Math | 75
Mary... | codefeedback |
Enhance the following code to find the average of all the even numbers in the array without using any loops or built-in functions:
my_array = [1,2,3,4,5,6]
Constraints:
- The input array can have up to 10^6 elements.
- The elements of the array can be positive or negative integers.
- The elements of the array can be ... | codefeedback |
Rewrite the following test with an increased level of difficulty:
Implement a function that takes in a string representing a JSON object and converts it into a valid JSON string, without using any built-in JSON formatting functions or libraries. The input string will always be in the format "{key: value, key: value, ..... | codefeedback |
Identify the specific type of object-oriented programming pattern used in the following code snippet. The pattern should support polymorphism, encapsulation, and the use of abstract classes. Additionally, the class should have at least two child classes that inherit the eat() method and override the move() method. One ... | codefeedback |
Create a list comprehension that outputs a list of prime numbers greater than 10 and less than 30 from a given list of numbers, while ensuring that the product of the resulting list is greater than 1000.
numbers = [10,11,12,13,14,15,16,17,18,19,20] | codefeedback |
Please rewrite the following code snippet using a switch-case statement and error handling. Additionally, add more reasoning steps to increase the difficulty.
```python
try:
result = 0
switch a:
case 0:
result = b * c
break
case 1:
result = b + c
... | codefeedback |
Create a class named "Person" containing the data members "name", "age", "address", "phone number", and "email address".
Additionally, add the following methods to the class:
1. A method named "get_full_name" that returns the full name of the person in reverse order (e.g. "Doe, John").
2. A method named "is_adult" th... | codefeedback |
Write a function that takes in two numeric variables x and y, and returns a boolean value indicating whether x is divisible by y or not. The function should have a time complexity of O(1).
However, you are not allowed to use any arithmetic operators (+, -, *, /) or any built-in functions that directly perform arithmet... | codefeedback |
Create a Java program to find the second most repeated word in a given string, ignoring case sensitivity and special characters. Additionally, you should remove any stopwords such as "the", "and", "in", and "a" before identifying the duplicates. | codefeedback |
Code an SQL query to get the records of all students with a grade of 'A' and have a score above 90 in the Student table. Additionally, display the average score of all students in the result.
Table Name: Student
Columns: id, name, grade, score
Note: The query should return the average score rounded to the nearest who... | codefeedback |
Analyze the following sentence and determine whether the dependent clause is restrictive or nonrestrictive. Provide the index position of the first character of the dependent clause.
Sentence: "The dog that was barking loudly chased the mailman."
Note: The dependent clause is a phrase or a clause that provides additi... | codefeedback |
Write a program that prints the sum of all prime numbers up to and including 1000. | codefeedback |
Create a function which returns the factorial of a given number, but only using recursion. The function should also handle negative numbers and return -1 for negative inputs. | codefeedback |
Read two strings from the user and check if they are anagrams. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. In addition to checking if the strings are anagrams, also check if they are palindromes. A palindrome is a word, phrase, number, or other sequence of characters that... | codefeedback |
Process this CSV string into an array of objects. Each object should contain the following properties: "name" (string), "age" (number), "gender" (string), and "country" (string). The CSV string should be processed using a custom delimiter instead of the comma (,).
Additionally, ensure that the "age" property is not a ... | codefeedback |
Explain the concept of hoisting in JavaScript and how it affects the handling of undeclared variables. Provide an example to demonstrate the behavior of hoisting in relation to undeclared variables, specifically in the context of function declarations and function expressions. | codefeedback |
Find the type of an object for the given object, but only using bitwise operations and without using any built-in type checking functions or operators.
Object: "Hello World" | codefeedback |
Write a code snippet to remove all the vowels from a given string, but keep track of the count of each vowel removed. Additionally, the code should also remove any duplicate vowels found consecutively. Return the modified string with the count of each vowel removed, in the format "vowel:count".
String: "Hello World!" | codefeedback |
Given a dictionary called 'data' which contains a nested list, how do you access the first element of the list without modifying the list? The list should remain the same: [6, 7, 8]. | codefeedback |
Write a JavaScript program to create an array of elements, representing the Fibonacci sequence, up to the given number n.
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1.
For example, if n is 10, the program should return [0, 1, 1, 2... | codefeedback |
Code an SQL query to insert new records into the Students table with the following requirements:
1. Only insert records if the grade is 'A' and the age is greater than 18.
2. Check if the name already exists in the table before inserting a new record. If it does, update the grade of the existing record instead of inse... | codefeedback |
Write a function that takes in a string representing an HTML page and removes all comments from it while maintaining the original formatting and structure. The function should use only recursion and cannot use any built-in HTML parsing libraries or regular expressions. Additionally, the function should handle nested co... | codefeedback |
Generate a query to count the number of unique values in a SQL table, but exclude any null values from the count. Additionally, you must ensure that the query is optimized for large datasets and should execute within a time complexity of O(nlogn). | codefeedback |
Write a function that creates a new array from a given array of integers, leaving out the negative ones, sorting the resulting array in ascending order, and removing any duplicates.
list1 = [-1, 1, 2, -2, 3, -3]
For example, if the input array is [-1, 1, 2, -2, 3, -3], the function should return [1, 2, 3].
Addition... | codefeedback |
Raise an error with the message "Invalid value" when the following function is called and the value of "n" is below 0. The function should also check if the value of "n" is greater than 1000000 and raise an error with the message "Value too large" if it is. The function should return the factorial of "n" if both condit... | codefeedback |
Read the integers in a given list and return the sum of the cubes of the list elements. The list can contain duplicate elements. The sum should be rounded to the nearest integer. You should handle any exceptions that may occur during the calculation. arr = [1, 2, 3] | codefeedback |
Write a function that takes in a dictionary as input and prints out the contents of the dictionary in a formatted manner. The dictionary may contain nested dictionaries and lists as values. Additionally, if a value in the dictionary is a list, print out the elements in reverse order. | codefeedback |
Split the following sentence into three words using regular expression and return the words in reverse order, but do not use the built-in split function. | codefeedback |
Read a list of strings and return a list which contains only the strings that start with a vowel, have length at least 5, and contain at least two consecutive vowels.
Example Input:
list = ["Apple", "cat", "ogre", "Eagle", "banana", "elephant"]
Example Output:
["Apple", "elephant"]
Note: In the example above, "ogr... | codefeedback |
Parse the data in the given json to a list of key-value dictionaries. The json may contain nested dictionaries and arrays. The final result should include all the key-value pairs in the json, including the ones in nested dictionaries and arrays. Additionally, handle cases where the json may contain duplicate keys and i... | codefeedback |
Create a loop in Python to print the first 100 prime numbers that are also Fibonacci numbers. | codefeedback |
Read an array of integers and sort it in increasing order. The array should have at least 10 elements and at most 200 elements. Each element in the array should be within the range of -10000 to 10000. If the array has duplicate elements, they should remain in their original order after sorting. Print the sorted array.
... | codefeedback |
Write an SQL query that displays the top 10 highest paid employees, ordered by salary. For each employee, also display the average salary of their department, as well as the average salary of their job title. | codefeedback |
Write a function in Python that takes a list of integers as input and returns the most frequent value(s) in the list. If there are multiple values that occur with the same maximum frequency, return all of them in a list, sorted in ascending order.
Example:
Input: [3, 9, 5, 6, 3, 9, 5]
Output: [3, 5, 9]
However, your... | codefeedback |
Create a function to compute the depth of a binary tree. The function should have a time complexity of O(n), where n is the number of nodes in the tree. Additionally, the function should use constant space, meaning it should not use any additional data structures to store the nodes. | codefeedback |
Write a code to group the elements in a list into a dictionary with the list element as the key and the number of times the element is repeated in the list as the value. The input list can contain any type of element, including nested lists and dictionaries. The code should be able to handle any number of nested levels... | codefeedback |
## Problem Statement ##
Generate a function to convert an infix expression to a postfix expression.
The infix expression can include the following operators: "+", "-", "*", "/", "%".
The expression can also include parentheses, which indicate the order of evaluation.
The expression can contain variables (single lette... | codefeedback |
Write a SQL query to find all flights departing from a given location after a given date and time, and arriving at a specific destination before a certain date and time. Additionally, the query should also filter out flights that have at least one stopover.
StartCity: NYC
Date/Time: March 16, 2021 8:00 AM
Destination... | codefeedback |
Edit this code to create a recursive function which prints the Fibonacci series in reverse order, while also calculating the sum of all the Fibonacci numbers within the series. Additionally, your function should take an integer input as the starting point for the series and should handle cases where the input is negati... | codefeedback |
Create a function in JavaScript to be used for capitalizing the first letter of each word in a string of text, while preserving the capitalization of any already capitalized words. Additionally, ensure that all punctuation marks and special characters are preserved in their original positions. | codefeedback |
Increase the difficulty of the given programming test question by asking the candidates to rewrite the function to use the modern function syntax and also handle cases where the name parameter is not provided or is an empty string. Additionally, require the function to handle cases where the age parameter is not provid... | codefeedback |
List all the items in an associative array named ‘inventory’. Additionally, sort the items in each category alphabetically. The time complexity of your solution should be O(n log n), where n is the total number of items in the inventory. | codefeedback |
Change the Python code to output the product of two numbers only if both numbers are positive. Otherwise, return an error message stating that both numbers must be positive. Additionally, the code should raise a custom exception called "NonPositiveError" if either of the numbers is not positive. | codefeedback |
You are given a list of numbers. Write a function to return a new list where each element at index i is the product of all other elements in the list except the element at index i. The input list will not contain any zeros.
Example:
Input: [1, 2, 3, 4]
Output: [24, 12, 8, 6]
Explanation:
For the element at index 0, t... | codefeedback |
Edit the following code to use more efficient algorithms to improve its performance. Additionally, the code should now handle negative values for n and ensure that the final result is within the range of a 64-bit signed integer. | codefeedback |
Create a function to find a pair of elements in an array whose sum matches the given target. If multiple pairs exist, return the pair with the highest sum. If no such pair exists, return an empty array.
# Example #
numbers = [1, 2, 3, 4, 5], target = 6
Output:
[4, 2]
Explanation:
The pairs that sum up to the target ... | codefeedback |
Create a JavaScript class named "Fruit" that holds the following properties: "Name" (a string representing the name of the fruit), "Color" (a string representing the color of the fruit), and "Price" (a number representing the price of the fruit).
The "Fruit" class should have the following methods:
1. "setName": a met... | codefeedback |
You are given a file containing a million records, where each record consists of a key-value pair. The keys are unique and consist of integer values ranging from 1 to 1 million. The goal is to sort the records based on their keys in ascending order. However, you are now required to implement a stable sorting algorithm ... | codefeedback |
Observe the given piece of code and suggest the possible data structure to use. Additionally, provide a more efficient solution with a lower time complexity.
for (int i = 0; i < input.length; i++)
{
if (input[i] == 0)
{
output[output_index] = i;
output_index++;
}
}
**Question:**
You are give... | codefeedback |
Generate a Python program to generate the square of all odd numbers from 1 to N, where N is an input from the user. The program should also calculate the sum of all the squares and display it as the output. | codefeedback |
Construct a JavaScript function that implements a fibonacci sequence. The function should not use recursion and should have a time complexity of O(n). Additionally, the function should not use any built-in mathematical functions or libraries and should handle input up to 10^6. | codefeedback |
Create discrete buckets in a given array using the following algorithm, where each bucket must contain at least three elements and the sum of the elements in each bucket must be a prime number. Additionally, each bucket should be sorted in ascending order.
[2, 3, 6, 7, 8] | codefeedback |
Edit the Python code to reverse a linked list with the following additional requirements:
1. The reversal must be done in-place, without creating any new nodes or using any additional data structures.
2. The time complexity of the solution must be O(n), where n is the number of nodes in the linked list.
3. The space c... | codefeedback |
Create an HTML table that contains 1 million rows and 100 columns. Each cell in the table should contain a randomly generated number between 1 and 100. Additionally, the table should be sortable by column, with a click on the column header sorting the table in ascending order based on the values in that column. The tab... | codefeedback |
Create a program to generate all subsets of a set, where each subset must contain at least one element from the original set. The program should also generate subsets in lexicographically increasing order.
input_set = {1, 2, 3, 4, 5}
Note: The program should be able to handle input_sets of any size, including large s... | codefeedback |
Create a class in Python that represents a geometric shape. The class should have the following properties and methods:
Properties:
1. "Color" (string) - represents the color of the shape.
2. "Height" (float) - represents the height of the shape.
3. "Weight" (float) - represents the weight of the shape.
Methods:
1. "... | codefeedback |
Increase the difficulty of the given programming test question by adding a specific requirement:
In the string_formatter function, modify the code to split the string into a list of words, remove any duplicate words, and then return the list of unique words in alphabetical order. The output should be a sorted list of ... | codefeedback |
Implement a program that calculates the result of a polynomial equation of degree 4 with specific coefficients.
The polynomial equation is: f(x) = ax⁴ + bx³ + cx² + dx + e.
The coefficients a, b, c, d, and e are randomly generated integers between -10 and 10 (inclusive).
Calculate and print out the result of the ... | codefeedback |
Create a class in Java called Student which contains string 'name', int 'grade', and a List of string 'subjects'. The 'subjects' list should store the names of the subjects that the student is enrolled in. The 'grade' should be between 0 and 100, inclusive. The 'name' should be at most 50 characters long and should not... | codefeedback |
Generate code for a for loop to iterate through the odd numbers from 1 to n, where n is a positive integer. Print out each odd number. Additionally, for every iteration, check if the current odd number is divisible by any of the previous odd numbers that were already printed. If it is, skip printing that number.
n = 1... | codefeedback |
How would you convert this list of strings to integers in Python? And then, sort the list in descending order based on the sum of the digits of each number?
str_list = ['123', '456', '789', '101112'] | codefeedback |
Write a function to make an API call to the Yelp API to return the list of top 10 restaurants near a given address within a specific price range. The function should also display the average rating and the number of reviews for each restaurant.
Address: 1234 Main Street, San Francisco, CA
Price range: $ - $$$
You nee... | codefeedback |
Create a Python function to generate a random hex color code with a specific length of n. The function should also include an optional argument to specify whether or not the color code should be a light or dark shade. Additionally, the function should validate that the generated color code is unique and has not been us... | codefeedback |
Train a classification model to classify the sentiment of the given sentence, taking into account the length of the sentence. The model should accurately classify the sentiment of sentences with a minimum length of 15 words. Sentence: I absolutely adore this fantastic new book that I recently purchased! | codefeedback |
Write a function that takes an integer as input and prints out all the prime numbers up to and including the provided number. Additionally, ensure that the function also checks for any invalid inputs and handles them accordingly.
#Erroneous Code Example#
```python
def is_prime(num):
if num < 2:
return Fals... | codefeedback |
Find the longest substring containing only consecutive digits from within the given string. The substring must contain at least k digits, where k is a parameter provided to the function. Additionally, the substring must be in non-decreasing order of digits. | codefeedback |
Create a function to calculate the network's throughput given a data rate, a size of the packets, the network's efficiency factor, and the network's error rate.
Data Rate = 10 Mbps; Packet size = 1000 bits; Efficiency factor = 0.8; Error rate = 0.05% | codefeedback |
Create a function that takes in two strings and returns the number of times the first string is found within the second string, considering that the search should be case-insensitive. The function should also handle cases where the first string is empty or contains non-alphabetical characters. Additionally, the functio... | codefeedback |
What is a heuristic for solving the traveling salesman problem and how does it work? Provide a detailed explanation of the steps involved in applying the heuristic to find an approximate solution. Additionally, your solution should consider a time constraint of O(n^2) for a given number of cities, where n represents th... | codefeedback |
Design an algorithm to find the longest substring with no repeating characters in a given string. The algorithm should also return the length of the longest substring.
Example:
Input: "abcabcbb"
Output: "abc"
Explanation: The longest substring with no repeating characters is "abc". The length of this substring is 3.
... | codefeedback |
Using any programming language, write a program which takes a number as an input and outputs the first three prime numbers after it. Additionally, the program should optimize the prime number checking algorithm to reduce the time complexity.
The program should have a time complexity of O(n√m) for checking if a number ... | codefeedback |
Create a program which takes a string and replaces all instances of the letter "e" with "X". Additionally, count the number of occurrences of the letter "e" in the string and display the count at the end.
Example:
Input: "Hello world"
Output: "HXLlo world"
Count: 1
Constraints:
- The input string will have a maximum ... | codefeedback |
Write a SQL query to find the most popular product by category, taking into consideration both the average rating, the number of ratings, and the price range for each product.
Table name: Products
Columns: category (String), product_id (Integer), rating (Integer), num_ratings (Integer), price (Integer)
The popularit... | codefeedback |
Implement a Sudoku solver algorithm that takes a partially filled Sudoku grid as input and returns a solved Sudoku grid. The algorithm should be able to solve Sudoku grids of size 9x9. You can assume that the input grid will always have a valid solution. Additionally, the algorithm should be able to solve Sudoku grids ... | codefeedback |
Given a list of integers, create an algorithm to sort the list in ascending order using a divide and conquer approach with a time complexity of O(n log n). The algorithm should not use any built-in sorting functions or libraries. The sorted list should be returned as the output.
1. Divide the list into two equal halve... | codefeedback |
Complete the program written in Java to add two numbers and print out the sum. However, you are not allowed to use any arithmetic operators (+, -, *, /) or Java built-in functions or methods to perform the addition operation.
int a = 3;
int b = 5; | codefeedback |
Write an SQL query to find the longest length of movies in a database called "Movies", where the length of a movie is defined as the duration in minutes. The query should exclude movies that have a rating lower than 7.0 and should only consider movies released in the past 5 years. Additionally, the query should also ex... | codefeedback |
Design a function in Python which takes a list of sentences as strings and returns a dictionary containing the frequency of each word in the sentences. Each sentence may contain punctuation, special characters, and numbers.
Example:
Input: ["I love apples!", "Apples are delicious! 123", "Do you like apples?"]
Output: ... | codefeedback |
Construct a JavaScript program to sort a two-dimensional array by the sum of the absolute differences between each element in column 1 and column 2, in descending order. If two or more sums are equal, sort those rows by the minimum value in column 3 in descending order. If the minimum values in column 3 are also equal,... | codefeedback |
Write a function that takes in two integers and returns True if the first integer is a multiple of the second integer, and False otherwise. The function should also check if either of the integers is negative, and if so, it should raise a ValueError with the message "Both integers must be positive". Additionally, the f... | codefeedback |
Create an API in node.js to get the details of a user using their email address. The API should validate the email address format and check if it exists in a database before returning the user details. Additionally, the API should only allow a maximum of 10 requests per minute from the same IP address to prevent abuse.... | codefeedback |
Write a JavaScript function that takes in an integer n and prints a specific pattern of numbers. The pattern should start with 1 and each subsequent row should contain numbers in increasing order up to n. The pattern should be printed in a zigzag manner, alternating between left to right and right to left. However, the... | codefeedback |
Create a JavaScript module to get the current day, month, and year, but the month should be returned as a string with the first letter capitalized and the year should be returned as a four-digit number. The module should also include a function to check if the current day is a weekday or a weekend day, and a function t... | codefeedback |
Construct a C++ program to find the maximum value in an array of integers using a divide and conquer approach. The array may contain negative numbers and has a size of n (1 <= n <= 10^6). The program should have a time complexity of O(nlogn) and should not use any built-in sorting functions.
Provide an erroneous code ... | codefeedback |
Generate a program to perform string formatting on a given string, but only capitalize the first letter of each word. Additionally, replace all occurrences of the letter 'o' with the number '0' and append the string " - Updated!" to the end of the formatted string. The program should handle strings with multiple whites... | codefeedback |
Create a function in Java to check if the sum of two given positive integers is greater than two times the second number. The function should also handle the case where either of the given numbers is negative and return false in such cases. Additionally, the function should handle the case where the sum of the two numb... | codefeedback |
Increase the difficulty by adding more reasoning steps:
1. Create a variable called "position" and set it to -1 initially. This variable will be used to store the position of the element in the list.
2. Use a for loop to iterate through each element in the list.
3. Inside the loop, check if the current element is equa... | codefeedback |
Create a function called "swap_list_elements" that takes three parameters: a list called "my_list", an integer called "index1", and an integer called "index2". The function should swap the values of the list elements at the specified indices and return the modified list.
In addition to the original requirements, the f... | codefeedback |
Write a program that reads a file containing multiple lines of code and deletes all comments that start with the string '#' from the given text. The program should output the modified code without the comments.
Example Input:
'''
The following program writes "Hello World!" to the screen. # This is a comment
print("Hel... | codefeedback |
Create a program to return all the prime numbers under the nth number, where n is a positive integer greater than 1.
To solve this problem, you can use the Sieve of Eratosthenes algorithm. This algorithm involves creating a boolean array of size n and initializing all the entries as true. Then, starting from 2, for ev... | codefeedback |
Implement a secure web service in Python to retrieve the current temperature from an external API. The service should require authentication using JWT tokens. Additionally, the service should have rate limiting in place to prevent abuse and ensure fair usage.
To further increase the difficulty, please include the fol... | codefeedback |
How would you create a recursive function to calculate the factorial of a given number in Python? Additionally, you should optimize the function to handle large numbers and provide an efficient solution with a time complexity of O(n). Your function should also check if the input is a positive integer and return an appr... | codefeedback |
Write a shell script to list the contents of a given folder and its subfolders, including all the files and directories within them. The script should display the complete path for each item listed. Additionally, the script should meet the following requirements:
1. The script should handle folders with spaces and spec... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.