instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a program that simulates a simple web server. The web server should be able to handle multiple client requests simultaneously and return appropriate responses based on the requested resources.
Requirements:
1. The web server should support the HTTP GET method.
2. The server should be able to handle multiple clie... | codefeedback |
Create a program to check if a number lies between two other numbers, but with the following constraints:
1. The program should have a time complexity of O(1) (constant time complexity).
2. The program should use only a constant amount of additional space (O(1) space complexity).
3. The program should be implemented u... | codefeedback |
Rearrange the characters of a given string in the order of their frequency, while ensuring that no two adjacent characters are the same.
String = "tree"
Constraints:
- The input string will only contain lowercase English letters.
- The input string will have at most length 10^5. | codefeedback |
Write an SQL query to calculate the sum of salaries from a table called 'employees' and display it along with the average salary. | codefeedback |
Develop an AI model to classify emails with spam contents, but with the additional requirement that the model must also be able to detect and classify emails with offensive or hate speech content. | codefeedback |
Write an Apache Spark code snippet to count the number of elements in an array of integers. The array must contain at least 1000 elements and the count must be calculated in parallel using multiple Spark partitions. | codefeedback |
Transform the string by swapping all lowercase characters with their respective uppercase characters and vice versa. | codefeedback |
Create a for loop to iterate through a given collection and print out both the index and the element for each iteration. Additionally, implement a nested if statement within the loop to print "Even" if the element is divisible by 2 and "Odd" otherwise. Finally, store all the even elements in a separate list and print i... | codefeedback |
Compute the union of two sets A and B using algorithms. You are not allowed to use any built-in functions or libraries for set operations. The input sets can contain duplicate elements and may not be sorted.
<[2,4,5,6], [1,2,3,4]> | codefeedback |
Given a string, replace every letter with its corresponding ASCII character code. If the character is a lowercase letter, add 32 to its ASCII code before replacing. If the character is an uppercase letter, subtract 32 from its ASCII code before replacing. The string may also contain special characters and numbers.
Exa... | codefeedback |
Write a MySQL query to update a table cell.
Update the 'salary' value from 20000 to 21000 for employee with the highest salary in the 'employees' table. Additionally, ensure that the 'salary' value is only updated if it is lower than 25000. | codefeedback |
Develop a natural language processing model to detect sarcasm in text, taking into consideration various languages and cultural contexts. The model should also be able to identify sarcasm in different mediums such as social media posts, emails, and chat conversations. Additionally, the model should provide an accuracy ... | codefeedback |
Write an SQL query to count the number of books of each genre, and display the result along with the genre name and the average rating for each genre.
Table Name: books
Attributes: id, title, author, genre, rating
Note: The rating attribute is a decimal value ranging from 0 to 5, representing the average rating given ... | codefeedback |
Given a SQL table named 'products', write a query to find all products with names starting with 'T' and have a price greater than 100.
Table Name: products
Attributes: name, price | codefeedback |
Create a Python class with three methods:
1. A method to add two numbers, but with the requirement that the implementation must use only bitwise operations (e.g., XOR, AND, OR, etc.) and no arithmetic operators (+, -, *, /).
2. A method to subtract two numbers, but with the requirement that the implementation must us... | codefeedback |
Write a SQL query to find all customers who have made a purchase on the same date that they made a purchase with a product price greater than 1000. Additionally, sort the result by the total amount spent by each customer in descending order.
Table Name: products
Attributes: id, name, price
Table Name: purchases
Attri... | codefeedback |
Create an HTML form to take user input with two fields: one for the user's name and another for their email address. Implement form validation to ensure that the name field only accepts alphabetic characters and the email field only accepts valid email addresses in the format "example@example.com". Additionally, displa... | codefeedback |
Write a Java program to create a calculator using Switch statement that supports addition, subtraction, multiplication, and division. The program should also include error handling for invalid inputs and division by zero. | codefeedback |
Write an R script to find all entries of a data frame where the 'Name column' equals 'John' and the 'Age column' is greater than 25. | codefeedback |
How can we create a class in C++ to represent a point on a 2D plane, with additional functionalities to calculate the distance between two points and to check if a given point is within a specified range from another point? | codefeedback |
Write SQL code to remove duplicates from a database table, but do not use any built-in functions or temporary tables.
Table name: Items
Columns: ID, Name | codefeedback |
Explain in your own words what is a pointer in C++. Provide a practical example of using a pointer in a C++ program and explain the potential risks and benefits of using pointers in programming. | codefeedback |
Explain the concept of pointer and reference variables in C++ and provide a detailed comparison of their similarities and differences. Additionally, provide examples illustrating their usage in different scenarios. | codefeedback |
Write a shell script to find the longest string from an array of strings. The script should also exclude any strings that contain digits or special characters. | codefeedback |
Write a query in MongoDB to select an item with a price greater than $10 and a quantity less than 5. | codefeedback |
Write a Java method which will print the Fibonacci sequence based on a given number, but with an improved time complexity of O(n) and without using recursion.
#Solution# | codefeedback |
Write an HTML page to display a table of products at a retail store, where the table should be sortable by any of the attributes. Additionally, include a search bar that allows the user to search for products by name or description, and dynamically update the table to display the search results in real-time. The table ... | codefeedback |
Create an object-oriented program that calculates the cost of a given item including sales tax and import duty.
Item cost (without tax): $10
Input tax rate: 10%
Input import duty rate: 5% | codefeedback |
Write a JavaScript code snippet to open a new window with some given URL, but also ensure that the new window has a specific width and height of 500 pixels each. The URL must also be validated to ensure that it starts with "https://" and ends with ".com". | codefeedback |
Write a recursive function to calculate the sum of all elements in an array of numbers. The function should not use any loops or built-in sum functions.
array=[1, 2, 3] | codefeedback |
Create an Apache Spark program written in Scala that takes in an RDD of integers and returns a new RDD where each element is the sum of its immediate neighbors. For example, given the input RDD [1, 2, 3, 4], the output RDD should be [3, 4, 6, 7].
Note: The first and last elements in the input RDD should only have one ... | codefeedback |
Write a Java code snippet to take input from the user and print the result. The input should be a string of numbers separated by commas, and the program should calculate the sum of all the numbers in the string. The program should also handle cases where the input is invalid, such as if the input contains non-numeric c... | codefeedback |
Create a Python script to find the greatest common divisor (GCD) of a pair of integers. However, the time complexity of the solution should not exceed O(log(min(a,b))) where a and b are the input integers. Additionally, the space complexity of the solution should be O(1) (i.e. constant space).
Number 1: 123456789
Num... | codefeedback |
Design a class in Java to represent a person's contact information like name, phone number, email address, and home address. The home address should include the street name, city, state, and postal code. The class should have methods to validate the phone number and email address. Additionally, the class should include... | codefeedback |
Create a JavaScript program that generates the Fibonacci sequence up to a given number provided by the user. The program should print out the Fibonacci sequence in reverse order and also calculate the sum of all the numbers in the sequence. | codefeedback |
Create a function in JavaScript which prints all twin prime numbers up to a given number.
(Note: Twin prime numbers are a pair of prime numbers that differ by 2, for example, (3, 5), (11, 13), (17, 19), etc.) | codefeedback |
Write a script in Python to sort a list of words alphabetically in descending order, while ignoring case sensitivity. The script should also remove any duplicate words from the list before sorting. | codefeedback |
Create a function in Python to remove all characters other than letters and numbers from a string. Additionally, any letter that is capitalized should be converted to lowercase, and any duplicate letters or numbers should be removed, so that only unique letters and numbers remain in the string.
string = "ThiS#%&strinG... | codefeedback |
Write a shell command to print out the environment variable $PATH, but only display the directories that are writable by the current user. | codefeedback |
Create a Python function which takes a nested dictionary and prints the contents of the dictionary in a human readable format, with each key-value pair indented according to its level of nesting. | codefeedback |
Write some HTML+CSS to create a navigation bar for a website with the following requirements:
- The navigation bar must have a fixed position at the top of the page and remain visible even when scrolling.
- The navigation bar must have a dropdown menu for the "Products" section, displaying sub-categories such as "Elect... | codefeedback |
Write a SQL query to update the "job" column of the "employees" table to "engineer" for all rows with the "department" column value "IT" and the "salary" column value greater than $50,000. | codefeedback |
Create a function in PHP to retrieve the contents of a given URL using the cURL library and display the HTML title tag of the retrieved webpage. | codefeedback |
Implement a function in any programming language that takes an integer n as input and prints the sum of all prime numbers up to n.
Requirements:
- The function should have a time complexity of O(n log(log n)).
- The function should not use any external libraries or built-in functions to check for prime numbers.
- The ... | codefeedback |
Write a function to identify all palindromes in the given string. The function should have a time complexity of O(n), where n is the length of the string. | codefeedback |
Provide a solution to print the following string in reverse order while excluding any vowels and special characters.
String = "Hello, world!" | codefeedback |
Create a class for customer data that includes the following requirements:
1. The class should have private member variables to store the customer's name, email address, and phone number.
2. The class should have public getter and setter methods for each of the member variables.
3. The setter methods should validate t... | codefeedback |
Create a function in Java to detect if an input string is a palindrome, but with the following additional constraints:
- The function must be case-insensitive, meaning that "racecar" and "Racecar" should be considered palindromes.
- The function must ignore all non-alphanumeric characters, such as spaces, punctuation, ... | codefeedback |
Write a JavaScript code snippet to set a value for a cookie, but the cookie must be encrypted using AES encryption algorithm with a randomly generated key before being stored. | codefeedback |
Write a Python program to find the closest number in a given array to a given number. The array and the number will always be provided. However, if the array is empty, the program should return an error message. If the given number is not present in the array, the program should return the closest number in the array. ... | codefeedback |
Create a responsive navigation bar using HTML and CSS. The navigation bar should have the following requirements:
- It should be a horizontal menu with each menu item displayed inline.
- When the user hovers over a menu item, the background color should change.
- The active menu item should be highlighted with a differ... | codefeedback |
Create a function in Python that takes in a positive integer N as input. The function should generate an array of N random strings, each consisting of lowercase alphabets and have a length between 5 and 10 characters. The function should return the generated array. | codefeedback |
Create a class in Python called Cat with a constructor that takes four arguments i.e. name, color, age, and breed. The class should have four methods called meow, purr, display_info, and set_breed. The set_breed method should validate that the breed is one of the following: Siamese, Persian, Maine Coon, or Bengal. If t... | codefeedback |
Create a program in Java that finds the maximum element in an array. However, instead of using a built-in function or method, you must implement your own algorithm to find the maximum element.
Your algorithm should not use any sorting functions or loops that iterate through the entire array. Instead, you must find the... | codefeedback |
Sort the following array of numbers [7,2,4,1,9] in descending order using JavaScript.
Additional requirements:
- You are not allowed to use any built-in sorting functions or libraries.
- You must implement your own sorting algorithm.
#Hint#
One possible solution is to implement the bubble sort algorithm. | codefeedback |
Create a web page using HTML and CSS that contains a heading, a button, and a form. When the button is clicked, the form should be validated to check if all required fields are filled out. If any required fields are empty, display an error message next to each empty field. Additionally, the button should change color w... | codefeedback |
How to delete a specific item from a Python dictionary if the dictionary has nested dictionaries and the deletion should be done recursively? | codefeedback |
Given an array of integers, write an algorithm to reorder the array so that all the negative integers appear before all the positive integers, while maintaining the relative order of the negative integers and the relative order of the positive integers. Your algorithm should have a time complexity of O(n) and should no... | codefeedback |
Write a method to remove the trailing spaces from a string in Python. The input string will contain alphanumeric characters, spaces, and punctuation. You are not allowed to use built-in functions or libraries to solve this problem. | codefeedback |
How to generate a random number between two given numbers without using any built-in random number generator functions or libraries in Python? | codefeedback |
Write a method to find the maximum number of consecutive subarrays in an array such that the sum of each subarray is equal to a specified number. The subarrays must have a length of at least 3.
arr = [1, 2, 3, 4, 5, 6, 7] | codefeedback |
You are given a dictionary in Python containing student names as keys and their corresponding scores as values. Write a function that takes this dictionary as input and returns a new dictionary with the students sorted in descending order based on their scores. | codefeedback |
Write a JavaScript function to calculate the length of a given string without using the built-in `length` property or any other string manipulation methods. | codefeedback |
Create a class in C++ called Point that represents a point in the two-dimensional space. The class should have the following features:
1. Private member variables to store the x-coordinate and y-coordinate of the point.
2. Public member functions to:
- Set the x-coordinate and y-coordinate of the point.
- Get th... | codefeedback |
Write a function to join a list of strings using a given character. The time complexity of your solution should be O(n), where n is the total number of characters in all the strings combined. | codefeedback |
How can you remove all the empty strings from a list while maintaining the order of the remaining elements? | codefeedback |
Code a for loop that iterates over a list of strings and capitalizes the first letter of each string. However, make sure to handle cases where a string starts with a number or special character. If a string starts with a number or special character, skip capitalizing the first letter and instead capitalize the second l... | codefeedback |
Find the smallest positive number that is not present in a given list.
You are given a list of integers, `my_list`, which may contain both positive and negative numbers. You need to find the smallest positive number that is not present in the list.
To solve this problem, you can follow these steps:
1. Initialize a v... | codefeedback |
Compose a program to create a dictionary of characteristics from a given list. Each item in the list represents a fruit, and the characteristics of each fruit should include its color, taste, and size. The fruits in the list are: "Apple", "Orange", "Grapes", "Bananas", "Watermelons". | codefeedback |
Generate the nth Fibonacci number using a loop, but also handle negative values of n by returning -1 for invalid inputs. | codefeedback |
Create a function in Python that takes a sentence as input and returns a dictionary of each word and its frequency in the sentence. The function should ignore punctuation marks and consider words with different letter casing as the same word.
Example:
Input: "The quick brown fox jumps over the lazy dog."
Output: {'th... | codefeedback |
Create a function in Java that takes two strings and returns an integer that describes the number of characters they share in common. The function should consider both uppercase and lowercase characters as the same.
string1 = "Hello"
string2 = "world"
Example:
Input:
string1 = "Hello"
string2 = "world"
Output:
1
Ex... | codefeedback |
Given a list of strings, create a Python function that sorts them in alphabetical order. Additionally, the function should ignore the case of the letters while sorting. The function should return the sorted list as output. The input list may contain duplicate strings, and the function should handle and preserve the dup... | codefeedback |
Write a program that prints a random permutation of an array of integers. The program should follow these steps:
1. Take an input from the user for the length of the array.
2. Generate a random number between 1 and 1000 and assign it to a variable `seed`.
3. Initialize an empty array `numbers`.
4. Generate `length` nu... | codefeedback |
Write a function to convert an anagram of a string to a dictionary. The anagram must contain only lowercase alphabetic characters and must not exceed a length of 10. The resulting dictionary should only include words that have at least 3 unique letters and have a length of at least 4 characters. The function should han... | codefeedback |
Calculate the Euclidean distance between two arrays, where each array contains 10,000 randomly generated numbers between 0 and 100,000. | codefeedback |
Write code in C++ to reverse an array of elements without using any additional arrays or data structures. | codefeedback |
Implement Naive Bayes for classification on a large dataset with multiple features and classes. Additionally, incorporate Laplace smoothing to handle zero probabilities. | codefeedback |
Implement a deep convolutional neural network with batch normalization and residual connections for image regression. | codefeedback |
Produce a regular expression that checks if a string contains between 10 and 30 characters, where the first character must be a lowercase letter, the last character must be an uppercase letter, and the remaining characters can be any alphanumeric character. | codefeedback |
Construct a regular expression that extracts substrings that match the pattern "AAA_BBB_CCC" and are followed by either "DDD" or "EEE". | codefeedback |
Generate an SQL statement to select the maximum salary of an employee from the given table, but only for employees who have been with the company for at least 5 years. Table Name: EMPLOYEE Table Rows: ID (int); NAME (string); SALARY (int); START_DATE (date)
#Reasoning Steps#
1. Connect to the database and select the E... | codefeedback |
Create a SQL query to get the count of students who have achieved the highest marks in each subject. Assume that the table structure is as follows:
Table Name: STUDENTS
Table Columns: NAME (string); SUBJECT (string); MARKS (int)
Note: You may need to use subqueries or join statements to achieve the desired result. | codefeedback |
Write code in Java to calculate the minimum number of coins needed to make change for a given amount, but with the constraint that you can only use each coin denomination once.
Coin denominations: [1, 2, 5, 10, 20, 50]
Amount: 34 | codefeedback |
Create a `Person` class that represents a person's information, including their name, age, gender, and contact information. Include appropriate data types for each attribute. | codefeedback |
Write a function to delete a node from the given linked list, where the linked list is sorted in ascending order.
Linked list: 1 --> 3 --> 5 --> 7 --> 9
Node to delete: 5 | codefeedback |
Create a class in C++ called "PreciseNumber" that defines a number as a double value and includes the following additional requirements:
1. The class should include a constructor that takes in a string representation of a number and converts it into a double value.
2. The class should include a method called "getRound... | codefeedback |
Given an input string and a pattern, find the first index of the pattern in the string. The pattern can contain wildcards represented by the '*' character, which can match any sequence of characters (including an empty sequence). The pattern can also contain '?' character, which can match any single character.
string:... | codefeedback |
Generate a function in Java to calculate the sum of all prime digits for any given integer.
Additional requirement: The function should have a time complexity of O(n), where n is the number of digits in the input integer. | codefeedback |
Create a JavaScript class for a student that includes properties such as first name, last name, and grades for all courses taken. The class should have methods to add a new course with a corresponding grade, calculate the average grade for all courses taken, and return the highest and lowest grades. Additionally, imple... | codefeedback |
Compose a piece of HTML code that uses a form to let the user input an email address and password. Upon submission, validate the email address to ensure it follows the correct format (i.e., contains an '@' symbol and a valid domain). Additionally, implement password validation by checking if the password is at least 8 ... | codefeedback |
Reverse the characters in each word of a sentence stored as a list in Python.
['drow', 'eno', 'si', 'siht'] | codefeedback |
Write a JavaScript program to make a shallow clone of an object, ensuring that all properties of the cloned object are in uppercase and are sorted in descending order. | codefeedback |
Write a function that takes two strings as parameters and returns a new string that has the characters of the second string appended to the first string. Additionally, the function should remove any duplicate characters from the resulting string.
For example, given the strings "hello" and "world", the function should ... | codefeedback |
Create a computer program that takes a string as an input and builds a dictionary of words and their respective frequencies. The program should also ignore any punctuation marks and convert all words to lowercase before counting their frequencies.
For example, given the string "The quick brown fox jumps over the lazy ... | codefeedback |
Design an algorithm to compute the number of trailing zeroes in a factorial number, but with the restriction that you are not allowed to use division or modulo operations. | codefeedback |
Create a function in JavaScript to generate an array containing 10 unique random numbers between 1 and 100 (inclusive) in ascending order. | codefeedback |
Create a method in JavaScript that will return the area of a triangle, but without using any built-in mathematical functions or operators for multiplication and division. | codefeedback |
Design an algorithm to calculate the intersection of two given lists. The lists can contain duplicates and may not be sorted. The resulting intersection list should also contain duplicates if they exist in both input lists.
List1 = [2, 5, 9, 12, 17, 5, 9]
List2 = [3, 5, 9, 10, 3, 5, 9]
Please provide a solution with ... | codefeedback |
How many lines would the following algorithm require?
# Find all the prime numbers between two given numbers
# Input: two numbers, n1 and n2
# Output: list of prime numbers between n1 and n2
**Algorithm:**
1. Initialize an empty list called "prime_numbers".
2. For each number i in the range from n1 to n2, inclusive:
... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.