instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Develop an algorithm that checks for balanced parentheses in a given string. The string can contain other characters besides parentheses. You need to consider three types of parentheses: round brackets (), square brackets [], and curly brackets {}. A string is considered balanced if every opening parenthesis has a corr... | codefeedback |
Design a machine learning model to classify an article into multiple categories, including sports, food, technology, politics, and entertainment. Additionally, the model should be able to determine the sentiment of the article, classifying it as positive, negative, or neutral. | codefeedback |
Create a Java function that takes an integer array as a parameter and prints out the maximum element of the array. However, you are not allowed to use any built-in functions or libraries to find the maximum element, and you must implement your own algorithm with a time complexity of O(n) or less. Additionally, the func... | codefeedback |
Develop a web page which takes user inputs and validates them. Implement the following validation rules:
1. The username field should not be empty and should contain only alphabets. Additionally, it should not exceed a maximum length of 20 characters.
2. The email field should be a valid email address and should not e... | codefeedback |
Write a code snippet to compute the median of a set of integers. Handle cases where the set has an odd or even number of elements.
#Difficulty Increased Explanation#
The original test asked for the average of a set of integers, which is a relatively simple task. By changing it to compute the median, we are increasing ... | codefeedback |
Edit the following program to add 1 to each element of the list and print the result. Additionally, you must implement the solution using a recursive function and ensure that the final result is stored in a new list without modifying the original list. In addition to this, you need to implement the solution in a way th... | codefeedback |
Design a neural network model to detect the sentiment of a given sentence. Additionally, the model should be able to handle noisy and unstructured data, such as misspelled words, grammatical errors, slang language, and emoji usage. The model should be trained on a dataset that includes a diverse range of emoji represen... | codefeedback |
Edit the following code to take in a list of numbers and output the sum of all numbers in the list. The code should also handle cases where the input list contains nested lists, and calculate the sum of all numbers within the nested lists as well. Additionally, the code should ignore any non-integer elements within the... | codefeedback |
Write a Python program to count how many times a given element appears in the list and return a list of tuples containing the element and its count in descending order of count.
Example:
Input:
my_list = [1, 2, 5, 4, 2, 1, 5]
Output:
[(1, 2), (5, 2), (2, 2), (4, 1)]
Note:
- The input list can contain integers, floats... | codefeedback |
Debug the following C++ program and also modify it to calculate the sum, difference, and product of two numbers, as well as the quotient and remainder when the first number is divided by the second number.
#include<iostream>
using namespace std;
int main()
{
int a, b;
cout<<"Enter two numbers: ";
cin... | codefeedback |
Generate all possible permutations of a given list of numbers, including duplicates. The input list can contain duplicate elements, and the output should also include duplicate permutations. The time complexity of the solution should be less than O(n!). Additionally, you must ensure that the generated permutations are ... | codefeedback |
Design a web scraper in Python to extract the text content from Wikipedia articles. Your scraper should be able to handle the case where the articles have dynamic content loaded through JavaScript. Additionally, the scraper should only extract the text content from articles that have been updated within the last 24 hou... | codefeedback |
Design a data structure to store a list of courses with their corresponding details. The data structure should support the following operations:
1. Add a new course with its details to the data structure.
2. Remove a course from the data structure.
3. Update the details of a course in the data structure.
4. Retrieve t... | codefeedback |
Write a Java program that takes in 3 strings, each containing at most 50 characters, and combines them into one in reverse order. The program should reverse the order of the characters within each string before combining them. Additionally, the program should remove any duplicate characters in the final combined string... | codefeedback |
You are given a list of names. Create a new list whose elements are the lengths of each name in the original list. Each name in the original list should be at least 3 characters long and contain only alphabetic characters. The resulting list should be sorted in descending order based on the length of the names. If two ... | codefeedback |
Modify the following code to print the keys of a dictionary in reverse alphabetical order. Additionally, the code should only print keys that have a value greater than 1. The code should also be implemented in a recursive manner and should not use any built-in functions or methods for sorting the keys or filtering the ... | codefeedback |
Read a sentence from the user, which will contain only letters and spaces. Reverse the words in place, but do not use any additional data structures or built-in functions for string manipulation. Additionally, ensure that the solution has a time complexity of O(n), where n is the length of the sentence. | codefeedback |
Write a JavaScript function to generate a random string of 12 characters using a combination of lowercase and uppercase alphabets, digits, and special characters. The special characters should include at least one of the following: !@#$%^&*()_+=-{}[]\|:;""'<>,.?/
Additionally, make sure that the generated string conta... | codefeedback |
Create a program that generates a random sequence of numbers between 0 and 10,000, and calculates the square root of each number. The program should then sort the square roots in ascending order and output the sorted list.
Note: You are not allowed to use any built-in sorting functions or libraries for sorting the squ... | codefeedback |
Construct a loop that prints the characters of the given string in reverse order, without using any built-in string manipulation functions or data structures (e.g. string[::-1], reversed(string), list(string), etc.). The loop should have a time complexity of O(n), where n is the length of the string. Additionally, you ... | codefeedback |
Create a Java program to determine whether a given string is a palindrome. A palindrome is a string which reads the same forwards and backwards.
Additionally, the program should handle the following cases:
1. The input string may contain both uppercase and lowercase letters, and it should still correctly identify pal... | codefeedback |
Construct a for loop in Java for iterating through a 2D array and print out each element, but only print out the elements that are prime numbers.
The time complexity requirement for this question is O(n^2), where n is the size of the 2D array. | codefeedback |
Form an if-else condition that prints “This is an even number” if a number is even, “This is an odd number” if the number is odd, and "This is a prime number" if the number is a prime number. Additionally, the program should also print the factors of the number if it is not prime. The program should also check if the n... | codefeedback |
Create an algorithm for finding the least common multiple of three numbers, using only prime factorization and without using any built-in mathematical functions or libraries. | codefeedback |
Write a SQL query to extract the top 5 occurrences of the city names from the following table, but only include cities that have at least 3 people living in them. Additionally, sort the cities in descending order based on the average age of the people living in each city. | codefeedback |
Rewrite the following Java code into SQL to select all the distinct elements from a table, where the elements must have a value greater than 100 and be sorted in descending order based on their values. The SQL statement should also include a limit of 10 for the number of results to be returned. Additionally, you need t... | codefeedback |
Make a dictionary that contains the number of characters in each word from this list. Each word must be processed in parallel using multithreading or multiprocessing. Additionally, the dictionary should only include words that have at least 7 characters and contain at least one special character. The final dictionary s... | codefeedback |
Design a RESTful API that allows users to create, read, update, and delete customer information. The API should only return the information if the user requesting the data has a specific role assigned to them. Additionally, the API should have rate limiting implemented to prevent abuse and ensure fair usage of the API.... | codefeedback |
Increase the difficulty:
Change the program to accept a string and a list as inputs. The program should then print each element of the list on a new line, with the string as a prefix for each element. Additionally, the program should print the total number of elements in the list at the end. The list can contain dupli... | codefeedback |
Write some Java code to fill in an array of size n with all prime numbers from 1 to n, where n is an odd number. Additionally, you should implement the code in a way that minimizes the time complexity. | codefeedback |
Write an assembly code to perform the task of incrementing a memory block by 16, but the memory block can only be accessed using indirect addressing mode. Additionally, the memory block must be a circular buffer, meaning that if the increment operation exceeds the maximum value of the memory block, it should wrap aroun... | codefeedback |
Create an HTML page that uses the CSS box model to style a text. The text should be inside a div element with a fixed width of 500px and a border of 1px solid black. The page should also include a button that changes the font color of the text when clicked. The font color should cycle through at least 5 different color... | codefeedback |
Create a Java program that prints a 10x10 multiplication table, but the table should only display prime numbers. Additionally, the program should implement a custom algorithm to efficiently check for prime numbers instead of using a built-in function or library. | codefeedback |
Write a program that takes in a list of integers and returns a new list containing only the odd numbers in the original list. The program should also sort the odd numbers in descending order before returning the new list. Additionally, the program should remove any duplicates from the resulting list and should handle c... | codefeedback |
Provide a syntactically correct C++ function called `numberToString` that takes a double precision floating-point number and returns a string representation of the number. The function should not use any built-in library functions for converting numbers to strings (e.g., std::to_string). The function should also handle... | codefeedback |
Create a regular expression to match all numbers of the form 1xx-xxx-xxxx, where xx cannot be greater than 50 and the last digit of the number must be odd. | codefeedback |
Write a loop that iterates over the characters in a string, and if the character is a vowel ('a', 'e', 'i', 'o', 'u'), print the character. Additionally, if the character is a consonant, convert it to uppercase before printing it. If the character is a special character or a number, skip it and continue to the next cha... | codefeedback |
Print a multiplication table for the number 7 in C, but also include the sum of each row at the end of the table. Each row should be sorted in ascending order. Additionally, the program should prompt the user to enter the number of rows to be printed in the table, and handle cases where an invalid number or a non-integ... | codefeedback |
Write a code to find the k-th largest value in a numeric array using recursion. The array may contain negative numbers. You can assume that the array will always have at least k elements, where k is a positive integer.
For example, given the array [1, -2, 3, -4, 5] and k = 2, the code should return 3 as the 2nd larges... | codefeedback |
You are given a list of HTML elements as strings and a specific element to insert at the appropriate place in the list. The list may contain nested elements. Your task is to insert the given element in the correct position in the list, while maintaining the nested structure of the elements.
For example, given the foll... | codefeedback |
Write a JavaScript code snippet to check for an empty array and return a message indicating whether the array is empty or not. Additionally, implement a function that removes the last element from the array if it is not empty. You are not allowed to use the built-in array methods such as length, pop, or push. | codefeedback |
Create a SQL query to select the most recent 5 posts from a table ordered by the post date. However, you should exclude any posts that have been flagged as inappropriate. Additionally, for each post, you need to display the username of the user who made the post and the total number of likes the post has received. Furt... | codefeedback |
Construct a decision tree to classify a fruit as mango or apple based on its color, texture, size, weight, taste, and smell, considering that the taste and smell should be evaluated separately for each fruit. Additionally, the decision tree should take into account the region and seasonality of the fruit as factors tha... | codefeedback |
Create a JavaScript class that takes in three arguments: a number, a string, and an array of objects. The class should store these arguments as properties and provide a method called "manipulateData" that performs the following operations:
1. If the number is even, multiply it by 3 and add 5.
2. If the number is odd, ... | codefeedback |
Construct a switch statement to check if a month name is valid. Additionally, handle the case sensitivity of the input and consider the possibility of the input containing leading or trailing whitespace characters. Furthermore, the month name should only be considered valid if it matches a specific set of names, which ... | codefeedback |
Create a command-line calculator program in Python that accepts two numbers as input and performs basic arithmetic operations (addition, subtraction, multiplication, division). The program should handle any invalid input gracefully and display an error message if necessary. The menu system should allow the user to choo... | codefeedback |
Use a random number generator to generate 10 random numbers between 1 and 1000. Implement a function that calculates the sum of all the generated numbers and returns the result. Additionally, you must ensure that the sum is always divisible by 3 and the sum of the even numbers is greater than the sum of the odd numbers... | codefeedback |
Create a function to decrypt an encrypted string. The encrypted string will be passed as an argument to the function. The encryption method used is a simple substitution cipher, where each letter in the string is replaced with a corresponding letter from a given alphabet. The alphabet used for encryption is provided as... | codefeedback |
Add a function to implement a calculator in C++ that supports addition, subtraction, multiplication, and division operations. The calculator should also handle parentheses and exponentiation. Additionally, the calculator should be able to evaluate expressions with trigonometric functions (sin, cos, tan).
You are give... | codefeedback |
Write a React class component that renders a greeting with a personalized message based on the current time of day. The greeting should include the user's name, which is passed as a prop to the component. Additionally, the component should change the background color based on the time of day, with a specific color pale... | codefeedback |
For the given array, output true if the array does not contain duplicates, output false if it contains any. The time complexity should be less than or equal to O(n^2). The space complexity should be less than or equal to O(n). The input array can have duplicates and can be unsorted.
Provide a piece of erroneous code a... | codefeedback |
Create a JavaScript function to check if a number is divisible by both 4 and 7 without using the modulus operator (%). | codefeedback |
Create a Spring boot program to find the area of a triangle given the lengths of its three sides, which are decimal numbers.
Additional requirements:
- The program should validate whether the given lengths form a valid triangle (i.e., the sum of any two sides should be greater than the third side) and display an appro... | codefeedback |
Write a multi-threaded application that calculates the sum of all prime numbers up to a given limit. The application should use a thread pool with a maximum size of 5 to divide the work among multiple threads for increased performance. Each thread should maintain a separate counter to keep track of the number of prime ... | codefeedback |
Write a program in a programming language of your choice that generates a random array of integers and sorts it using the Quicksort algorithm. Additionally, your program should also display the number of comparisons and swaps performed during the sorting process.
In order to increase the difficulty, your program shoul... | codefeedback |
Given two sorted arrays, find elements that exist in both arrays.
arr1 = [1, 2, 5, 8, 9, 10]
arr2 = [2, 5, 6, 9]
Please note that the arrays can have duplicate elements and the output should include all duplicates as well.
Write a function called "find_common_elements" that takes in two sorted arrays as input and r... | codefeedback |
Implement a function that breaks down a given text into individual words. The function should ignore punctuation marks and return a list of unique words in the text. Additionally, the function should ignore common English stop words such as "the", "and", "or", etc. The function should have a time complexity of O(n), wh... | codefeedback |
Write an optimized SQL query to retrieve the records with age greater than 25 and address in Mumbai from a table with a large number of records (e.g. billions of rows). Ensure that the query executes efficiently and returns the results in a timely manner. Additionally, consider that the table has multiple columns and j... | codefeedback |
Create a CSS property to remove both the vertical and horizontal scrollbars from a webpage, while maintaining the ability to scroll using touch gestures on mobile devices. Additionally, the solution should ensure that the scrolling behavior remains smooth and does not cause any performance issues, even when there is a ... | codefeedback |
Print out the length of each string in the list, but only for strings that contain at least one uppercase letter and do not contain any special characters.
list_of_strings = ['Hello', 'W0rld', 'f@@bar', 'T!st'] | codefeedback |
Write code to create an object with the key which will be incremented by the next prime number on every call of the code, starting from a given initial key value. | codefeedback |
Convert each element of the list into lowercase, concatenate them into a string, and count the number of unique vowels in the resulting string.
list_of_strings = ['I', 'am', 'a', 'string'] | codefeedback |
Write CSS code to create a responsive navigation bar with the following requirements:
1. The navigation bar should be positioned at the top center of the page.
2. The navigation bar should have a fixed height of 60 pixels.
3. The navigation bar should have a background color of #333 and text color of #fff.
4. The navi... | codefeedback |
Swap the elements at index 2 and 4 only if the sum of the elements at index 0 and 1 is greater than the sum of the elements at index 3 and 4, and the difference between the maximum and minimum values in the array is less than or equal to 10.
arr = [1, 3, 5, 6, 8] | codefeedback |
Fix this indentation error in the following Python code. The solution should be a recursive function. Additionally, the solution should be implemented using only a single line of code. | codefeedback |
Reverse a given array's elements and print the resulting array. Additionally, calculate and print the sum of all the elements in the reversed array. The input array will contain up to 10^6 elements, all of which will be integers between -10^6 and 10^6 (inclusive). The solution should have a time complexity of O(n) and ... | codefeedback |
What data structure is most appropriate for fast searches when the number of elements is in the order of 10^9 and the search operation needs to be completed in less than 1 millisecond? | codefeedback |
Create code that, given a string, returns the longest substring of consecutive characters that contains at least one vowel. If there are multiple substrings with the same length, return the one that occurs first.
str = "abcccccdef" | codefeedback |
Create a new array from the given array by replacing all the odd numbers with 0. However, you should also replace all even numbers with their square root rounded to the nearest integer. The new array should be sorted in descending order and should not contain any duplicate values. The length of the new array should be ... | codefeedback |
Create code that will reverse the order of elements in this list and remove any duplicates, using only constant space complexity and a time complexity of O(n). | codefeedback |
Create a function that prints a provided message 3 times, but each repetition should be in a different color. The message can only contain alphabetic characters and should have a maximum length of 20 characters. Additionally, the function should also print the length of the message before printing the repeated messages... | codefeedback |
Create code to find the longest subarray with an equal number of 0's and 1's, where the subarray must also contain an equal number of even and odd numbers. Additionally, the subarray should have a maximum length of K.
list = [0, 0, 1, 0, 1, 2, 3, 4, 0, 1, 0, 0, 1]
K = 5 | codefeedback |
Create code that given a stack (i.e., a sequence of objects), returns the reversed stack without using any built-in functions or methods that directly manipulate the stack. Additionally, you are not allowed to use any additional data structures such as arrays or lists to store intermediate values during the reversal pr... | codefeedback |
Edit this code so that it can marshall a json object, but also include the following requirements:
1. Convert the "age" value to a string before marshalling.
2. Add an additional key-value pair to the "data" dictionary, with the key "city" and the value "New York".
3. Use a try-except block to handle any potential err... | codefeedback |
Create a function that will add two numbers (represented as linked lists). Each linked list node contains a single digit from 0 to 9, and the digits are stored in reverse order (i.e., the head node contains the least significant digit). The function should return a new linked list representing the sum of the two input ... | codefeedback |
Create a web page that displays a paragraph of lorem ipsum text. However, the text should be divided into multiple sections and each section should be displayed one at a time with a fade-in animation. The animations should occur at different time intervals, with each section fading in after a random delay between 1 and... | codefeedback |
Edit the following code snippet to add if/else logic for printing a success message and a failure message. Additionally, check if the sum of num1 and num2 is a multiple of 3 and print a corresponding message.
num1 = 5
num2 = 6
if num1 > num2:
print("The number is greater than 5.")
else:
print("The number is not gre... | codefeedback |
Create a function that, given two binary search trees with integer values, determines if they are identical. The function should consider the following additional constraints:
- The binary search trees can have duplicate values.
- The nodes of each tree can have an additional attribute called "color", which can take va... | codefeedback |
Construct an expression in javascript to reverse a string without using the built-in "reverse()" method or any other string manipulation methods like "split()" or "join()". The expression should also have a time complexity of O(n), where n is the length of the input string. | codefeedback |
Get the top ten most used words within a string, excluding any words that contain numbers or special characters. The string can contain up to 100,000 characters and the words can have a maximum length of 50 characters. Additionally, the algorithm should run in O(n log n) time complexity, where n is the number of words ... | codefeedback |
Write a code snippet to store the output of an API call into a variable and then encrypt the data using the RSA encryption algorithm with a randomly generated key and IV. The encrypted data should then be stored in a file. The API call should include the following headers: 'Content-Type: application/json' and 'Authoriz... | codefeedback |
Write an SQL query to fetch the top 5 products with the highest sale prices from a table named 'products', but exclude any products that have a stock quantity of 0. Additionally, the query should also exclude any products that have a sale price less than the average sale price of all products in the table. | codefeedback |
Create a multi-threaded REST API client that retrieves the latest version of Python from a remote server. The client should use asynchronous programming techniques to improve performance and handle any errors or exceptions that may occur during the API call. Additionally, you should implement a caching mechanism to sto... | codefeedback |
Construct a valid and optimized MySQL query to get the user details of all users who are younger than 24, have subscribed more than 10 times, and have a subscription status of "active". Additionally, exclude any users whose subscription has expired. | codefeedback |
Create a virtual machine using Terraform that automatically scales based on CPU usage and sends a notification to a specified email address when the scaling occurs. Additionally, implement a monitoring system that tracks and logs the CPU usage data for future analysis. | codefeedback |
Implement the merge sort algorithm to sort a given array of integers in ascending order. The array will contain at least 1 million elements and can have duplicate numbers. Additionally, you are not allowed to use any built-in sorting functions or libraries. | codefeedback |
Increase the difficulty of the given programming test question:
Construct a SQL query to find all clients who have placed orders for a specific product and their corresponding order details. The product name is "ABC".
Additional Information:
1. The database schema consists of three tables: "clients", "orders", and "p... | codefeedback |
Create a web application that allows users to input a list of numbers separated by commas and returns the median of the list. Display the median value on the page in a visually appealing format, such as a chart or graph.
Requirements:
1. The web application should have a clean and user-friendly interface.
2. The user ... | codefeedback |
Develop a gradient descent algorithm to optimize a non-convex cost function with multiple variables, inequality constraints, and a non-smooth penalty term for violations of the constraints. | codefeedback |
Create a function to build a queue (i.e., a sequence of objects) with the following requirements:
1. The queue should have a maximum capacity of 10 objects.
2. The queue should have the following methods:
- `enqueue`: Add an object to the end of the queue.
- `dequeue`: Remove and return the object at the front o... | codefeedback |
Create an API endpoint in NodeJS that returns a JSON object containing the current time in UTC format, along with the current weather condition and temperature for a specific location. The location can be provided as a query parameter in the API request. The weather condition and temperature should be retrieved by maki... | codefeedback |
Construct a pre-order traversal code to traverse a binary tree and print the nodes in reverse order. Additionally, implement a function to count the number of nodes in the tree. | codefeedback |
Edit the code to make sure the program prints the correct output, without using any arithmetic operators such as +, -, *, or /. Additionally, you must now solve the problem using only bitwise operators and control flow statements. | codefeedback |
Write a code to create a secure web server for a given web page, using SSL/TLS encryption and a valid SSL certificate. Additionally, implement client-side certificate authentication to ensure secure communication between the server and the clients. | codefeedback |
Create code that given two linked lists, determine if they intersect at a specific node. The intersection node must have a value that is a prime number. Additionally, the code must handle the case where one or both of the linked lists are circular, meaning they contain a loop where the last node points back to a previo... | codefeedback |
Create an array of 10 unique numbers between -100 and 100, with the constraint that the sum of all the numbers in the array must be less than 500. Additionally, the sum of the first 5 numbers in the array must be positive and the sum of the last 5 numbers must be negative. | codefeedback |
Modify the following code to kill a thread after a randomly generated time interval between 5 and 15 seconds.
import threading
import random
from time import sleep
def worker():
try:
while True:
print("Thread")
sleep(1)
except Exception as e:
print(e)
def kill... | codefeedback |
Create a vector in R to store the elements ‘apple’, ‘mango’, ‘banana’ and ‘orange’, ensuring that the vector can only contain unique elements and has a maximum size of 5. Additionally, implement a function that allows the user to add elements to the vector, but only if the element is not already present in the vector. ... | codefeedback |
Write a code in Python for comparing two strings without using any built-in function, loops, or recursion. The code should have a time complexity of O(n), where n is the length of the longer string.
string1 = "apple"
string2 = "orange"
# Expected Output
# False | codefeedback |
Write a function that takes two arguments, an array arr and a value x, and returns the number of times x appears in the array arr. The function should only iterate through the array once and should have a time complexity of O(n). Additionally, the function should not use any built-in methods or libraries to solve the p... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.