instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Implement a function that takes two strings and checks whether they are anagrams. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The function should return True if the strings are anagrams and False otherwise.
Example:
Input:
str1 = "listen"
str2 = "silent"
Output:
True
... | codefeedback |
Create a PHP script to log user activity, but ensure that the script can handle multiple concurrent users and store the activity logs in a database with proper data normalization.
Additionally, implement a feature to track the duration of each user's activity and calculate the total duration for all users.
Furthermor... | codefeedback |
Using CSS and HTML, create a responsive web page layout that includes a complex box shadow effect with multiple layers and gradients. The layout should also incorporate a fixed navigation bar, a sticky footer, and at least two media queries to adapt the design for different screen sizes. | codefeedback |
Create a CSS animation which will rotate a shape when the user hovers over it. Additionally, implement a functionality where the shape changes color randomly every time it completes a full rotation. Ensure that the shape also scales down gradually as it rotates. | codefeedback |
Given a list of student class enrollments, group students into classes that correspond with their major. Each student object contains the following attributes: "name" (string), "major" (string), and "age" (integer). The list may contain duplicate student objects.
Write a function named "group_students" that takes in t... | codefeedback |
Create a web page with a form for user input of a modified text. The modified text should contain only unique words in alphabetical order. The web page should also display the total number of unique words in the modified text. Additionally, implement a feature where the user can choose to sort the unique words in rever... | codefeedback |
Program a function that takes a list of numbers as an argument, then returns a dictionary which contains the number in the list as a key and its square root as the value. However, if the number is negative or not a numeric value, the function should raise an exception. The function should handle floating-point numbers ... | codefeedback |
Using an OOP approach, create an Animal class with properties of name, species, and a virtual property age that gets calculated based on the creation date and the average lifespan of the species. The Animal class should also have a method called "eat" that takes in a parameter of food and updates the animal's age based... | codefeedback |
Create a web application that allows users to register and login.
1. Registration:
- The registration form should include fields for username, email, and password.
- The username should be unique and alphanumeric, with a minimum length of 6 characters.
- The email address should be in a valid format (e.g. em... | codefeedback |
Write a function that reverses a given string without using any built-in string manipulation functions or methods and without using any additional data structures. The function should have a complexity of O(n), where n is the length of the string.
#Additional Requirements#
1. The function should be implemented using o... | codefeedback |
Program a function to convert a given string with no spaces to a string with underscores (_) in all spaces between words. The input string will consist only of uppercase and lowercase letters, and it may contain punctuation marks. The output string should have all words separated by a single underscore, and all punctua... | codefeedback |
Detect the sentiment of the given text and provide a detailed analysis of the sentiment by identifying the key factors that contribute to the sentiment.
The movie was a total disaster and a complete waste of time due to the poor acting, weak plot, and subpar special effects. The lack of character development and meani... | codefeedback |
Construct a SQL query to fetch all data from the given table and display only the employees who have a salary greater than $50,000. Additionally, sort the result in descending order based on the employees' hire dates. | codefeedback |
Create a function to calculate the sum of all the values in the given array. The array may contain negative numbers. However, if the array contains any values that are greater than or equal to 10, the function should skip adding them to the sum and instead print a warning message. The function should return the sum of ... | codefeedback |
Compare and contrast the key differences between class-based programming languages and prototype-based programming languages. Provide detailed explanations and examples to support your answer. | codefeedback |
Calculate the LCM (Least Common Multiple) of two integers, with the additional requirement that the LCM must be greater than 1000. Find the LCM of two integers, where the first integer is not divisible by 2, the second integer is not divisible by 3, and the sum of the digits of the LCM is a prime number.
int x = 111;... | codefeedback |
Generate a Python dictionary containing the squares of the numbers from 1 to n, where n is a positive integer less than or equal to 100. Each square value in the dictionary should be unique and the keys should be in ascending order.
Additionally, the solution should be optimized for both time and space complexity. The... | codefeedback |
Write a C program to find the longer of two strings, but without using any built-in string length functions or methods. The program should also handle cases where the lengths of the strings are equal, in which case it should return an error message. String x and y should be obtained from user input. | codefeedback |
Create a program for calculating the hypotenuse of a right-angle triangle using its two sides.
Input:
- Two positive integers, a and b, representing the lengths of the two sides of the right-angle triangle.
Output:
- The length of the hypotenuse, rounded to 2 decimal places.
Requirements:
- The program should handle... | codefeedback |
Using HTML and JavaScript, create a dynamic table showing a list of countries and their population. Implement functionality to sort the table based on population in ascending or descending order upon clicking on the respective column header. Additionally, allow the user to search for a specific country in the table usi... | codefeedback |
Write a Java program to find all prime numbers within a given range.
int start = 1;
int end = 100;
Additional Requirements:
1. Implement the Sieve of Eratosthenes algorithm to efficiently find prime numbers.
2. Use a function to check if a number is prime or not, instead of directly checking for divisibility by all n... | codefeedback |
Create a SQL query to find the rows that have a specific value in a column, but the column name should be dynamically passed as a parameter to the query. Additionally, the query should return the count of the rows instead of the actual rows. | codefeedback |
Develop a code in Python to update all the elements of an array by a number, but only for elements that are divisible by 2. The code should also remove any duplicate elements in the array and sort the array in ascending order after updating the elements.
a = [1, 4, 5, 7, 9] | codefeedback |
Complete the following line of code to successfully initiate a pandas dataframe without specifying column names or data. Additionally, ensure that the dataframe has 5 rows and 5 columns, and restrict the datatype of the data in each cell to only integers. | codefeedback |
Implement a thread pool in Java that supports dynamic resizing of the pool based on the current workload. Additionally, the thread pool should have a scheduling mechanism that prioritizes tasks based on their urgency and assigns them to threads accordingly. The scheduling mechanism should take into account not only the... | codefeedback |
Develop a script to remove duplicate elements from an array, but you are not allowed to use any built-in functions or libraries for removing duplicates or any additional data structures (such as dictionaries or sets). The script should have a time complexity of O(n^2) or less.
arr = [1, 2, 3, 4, 4, 1, 5] | codefeedback |
Generate the code to find the number of business days (excluding weekends and public holidays) between two dates. Additionally, ensure that the code handles time zones correctly and takes into account daylight saving time changes. | codefeedback |
Create a web application that allows users to register, log in, and upload and download files. The application should use a database to store user information and file metadata. Implement secure authentication and authorization mechanisms to ensure that only authorized users can access their own files. Additionally, th... | codefeedback |
Create a program that prompts the user to enter the length, width, and height of a triangular prism, and then calculates and displays the surface area of the prism. Additionally, implement error handling to validate the user inputs and handle any potential exceptions that may occur. | codefeedback |
Calculate the mean of the following list of numbers using a for loop. The list may contain up to 10^6 numbers. Additionally, the list may contain negative numbers and decimal numbers. | codefeedback |
Write a function that takes four parameters: a list of strings, an index of integers, an alphabet string, and a flag indicating whether duplicates are allowed. The function should return only the items from the list at the specified indexes using letters from the alphabet as keys. If the indexes are out of range, the f... | codefeedback |
Write a function to check if all the items in a list are of the same data type. The list can contain any valid Python data type, including nested lists and dictionaries. Your function should return True if all the items in the list are of the same data type, and False otherwise. You should aim for an optimal time compl... | codefeedback |
Develop a C program for swapping the values of two variables without using a temporary variable. Additionally, ensure that the program can handle swapping variables of different data types, such as swapping an integer and a character. | codefeedback |
Create a function to calculate the Pythagorean theorem given three sides of a triangle. The function should check if the given sides form a valid triangle by ensuring that the sum of any two sides is always greater than the third side, and if not, it should raise an exception. Additionally, the function should check if... | codefeedback |
Write a Bash script to create a directory with the following requirements:
1. The directory should be created with a random alphanumeric name consisting of 10 characters.
2. The script should check if a directory with the same name already exists. If it does, it should generate a new name and check again until a unique... | codefeedback |
Create a program to validate a string for a specific length and that also checks if the string contains only lowercase alphabets. Additionally, the program should check if the string contains at least one digit and one special character. | codefeedback |
Create an array of size n and populate it with the first n prime numbers. Your solution should have a time complexity of O(n√m), where n is the size of the array and m is the largest prime number in the array. Additionally, your solution should use O(n) space complexity. | codefeedback |
Write a function to extract the digits of a number in an array. The number can be positive or negative and may contain decimal points. The function should handle numbers up to 10^100 and return an array of the digits in the number.
In addition, the function should handle numbers with exponential notation, such as 1.23... | codefeedback |
Create a program that reads a string input and replaces all instances of a word with a given replacement. The program should handle multiple replacement words and should have a time complexity of O(n^2) and a space complexity of O(n), where n is the length of the input string.
Original string = "Merry Christmas everyo... | codefeedback |
Create a PHP function that takes two strings and returns a new string that consists of the first string repeated the number of times specified by the length of the second string. However, the function should only consider repeating the characters of the first string that are present in the second string. If there are c... | codefeedback |
Create a program to detect if an array contains duplicate values, while also keeping track of the indices of all duplicate values. Additionally, optimize the algorithm to have a space complexity of O(1) and a time complexity of O(n), where n is the length of the array. | codefeedback |
Generate a program that merges two sorted lists into one sorted list. The merged list should be sorted in descending order. Additionally, provide a piece of erroneous code as a reference to increase misdirection.
list1 = [10, 8, 6, 2]
list2 = [9, 7, 4, 3]
Erroneous code for reference:
```python
def merge_lists(list1... | codefeedback |
Write a function to find the length of the longest word in a sentence, where the sentence may contain punctuation marks, special characters, and numbers.
sentence = "Today is a beautiful day! The temperature is 25 degrees Celsius." | codefeedback |
Create a program to print all prime numbers from 1 to a given number, but the program should not use any loops or conditional statements, and should have a time complexity of O(sqrt(n)) where n is the given number. | codefeedback |
Combine the two functions, multiply() and divide(), into a single function called calculate(). The calculate() function should take in three arguments: two numbers (x and y) and a string (operation). The operation string can either be "multiply" or "divide" and should specify the desired arithmetic operation to be perf... | codefeedback |
Write a Haskell function that takes a list of integers and returns the sum of all the elements, but you are not allowed to use any built-in functions for addition or summation. | codefeedback |
Create a program that takes a string, which may contain punctuation marks and special characters, and prints the number of words the string contains. The program should also ignore any leading or trailing white spaces. The maximum length of the string should not exceed 100 characters.
Additionally, the program should ... | codefeedback |
Suggest a way to finish the following instruction.
Create a Java program to calculate the factorial of a given number using recursion with a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Create a PHP function that finds the maximum and minimum values of an array of integers. The function should have a time complexity of O(n), where n is the number of elements in the array. The function should not use any built-in PHP functions or sorting algorithms.
Additionally, the function should not use any additi... | codefeedback |
Write a function in Java that takes an integer and returns its square. The function should not use the multiplication operator (*) or any other arithmetic operators and should have a time complexity of O(1). The function should also not use any built-in mathematical functions or libraries. | codefeedback |
Write a code snippet to print out each item in a given array, but only print out the numbers that are divisible by 2. Additionally, you should print out the index of each divisible number in the array.
For example, for the input array [7, 4, 10, 3, 6, 9], the expected output should be:
Index: 1, Value: 4
Index: 2, Val... | codefeedback |
Please write a function that takes in a string and returns true if it is a valid URL, and false otherwise.
The function should check if the input string satisfies the following conditions:
- The string starts with either "http://" or "https://".
- The string contains at least one dot (".") after the prefix.
- The stri... | codefeedback |
Sort a given list in increasing order without using any built-in sorting functions or methods. Additionally, you are not allowed to use any additional data structures or create any helper functions. The list may contain duplicate elements. The solution should have a time complexity of O(n^2).
my_list = [3, 4, 2, 6] | codefeedback |
Write a program in JavaScript to find all prime numbers up to a given limit using a for loop. Additionally, implement an optimization technique such as the Sieve of Eratosthenes to improve the efficiency of the algorithm. | codefeedback |
Create a function that takes in two strings as parameters and returns a new string where each character from the first string is followed by its corresponding character from the second string. If the two strings are not of equal length, the remaining characters from the longer string should be appended to the end of th... | codefeedback |
Edit the given SQL statement to select the top 10 entries with the lowest price and the highest rating, excluding any entries with a rating lower than 4.5. Additionally, filter the result to only include products that have a quantity greater than 0.
SELECT * FROM products
WHERE rating >= 4.5
AND quantity > 0
ORDER BY ... | codefeedback |
Write a Java method to check if a numerical value is within a specified range and return the number of times the value appears in the range.
Signature:
```java
public static int countValuesInRange(int[] nums, int startRange, int endRange)
```
Input:
- An array of integers `nums` (1 <= nums.length <= 10^6) where each ... | codefeedback |
Write a program to calculate the area of a circle given its radius. The radius can be any positive real number. The program should output the area rounded to two decimal places.
However, the program should not use any mathematical library or built-in functions to calculate the value of pi. Instead, you should approxim... | codefeedback |
Calculate the sum of the digits in the given positive integer, excluding any digits that are divisible by 3. Additionally, the algorithm should have a time complexity of O(n), where n is the number of digits in the integer. | codefeedback |
Write a function in Python to remove all occurrences of a given element from a list and return the modified list. The function should have a time complexity of O(n) and space complexity of O(1), where n is the length of the list. Additionally, the function should not use any built-in Python functions or methods for rem... | codefeedback |
Create a function that takes in an integer 'n' and returns a list of all prime numbers smaller than or equal to 'n'. Additionally, the program should compute the sum of all prime numbers in the list. | codefeedback |
Create a class in C++ to calculate the volume of a rectangular box. However, the dimensions of the box should be stored as private member variables of a separate class called "Dimensions". The "Dimensions" class should have three private member variables: length, width, and height. Provide public member functions in bo... | codefeedback |
Print a list of numbers from 1 to 100, excluding multiples of 5 and 6, while also ensuring that the sum of the digits of each number is not divisible by 3. | codefeedback |
Write a function in Java to find the element that appears most frequently in the array. The array may contain duplicate elements and has a size of up to 1 million. Your function should have a time complexity of O(n) and a space complexity of O(1). Additionally, you are not allowed to use any built-in data structures or... | codefeedback |
Create a function to calculate the Fibonacci series from 0 to n. However, this time, you are not allowed to use recursion or any built-in functions or libraries to solve the problem. You should implement a purely iterative approach instead. | codefeedback |
Create a SQL query to select all items from a table named "products" that have a price greater than 50, and are sold by a specific seller with the highest total number of sales, ordered by the total number of sales in descending order. | codefeedback |
What is the time complexity of a binary search tree? Provide a piece of erroneous code as a reference to increase misdirection. Additionally, explain the process of balancing a binary search tree and its impact on the time complexity. | codefeedback |
Describe what a quicksort algorithm does and implement it in a programming language of your choice. Your implementation should include the ability to handle duplicate elements in the input array and should have a time complexity of O(nlogn).
Additionally, include error handling in your code to handle scenarios where t... | codefeedback |
Write a code to convert a string to a list of characters, without using any built-in string or list manipulation functions or methods (e.g. `split()`, `list()`, etc.). The code should have a time complexity of O(n), where n is the length of the string. Additionally, the code should handle strings with special character... | codefeedback |
Create a Python function to check if a given array is sorted in ascending order. The array must contain only positive integers (including 0) and have a length greater than 1. The function should return True if the array is sorted in ascending order, and False otherwise. If the array is not sorted in ascending order, th... | codefeedback |
Create a Python class that has an initialization method which takes in two parameters (both integers) and sets them as class variables. Additionally, the class should have a method called `calculate_sum` that calculates the sum of the two parameters and returns the result. The `calculate_sum` method should have a time ... | codefeedback |
Create a C++ function that takes in a sorted array in non-decreasing order and a value, and returns the index of the first occurrence of the value (if it exists) in the array. If the value does not exist in the array, return -1.
Additionally, the function should have a time complexity of O(log n), where n is the size ... | codefeedback |
Given 2 string variables, write a function to find out if the 2 strings are anagrams. Additional requirement: The function should be case-sensitive and ignore any spaces or special characters. Additionally, the function should also consider the frequency of each character in the strings and return True only if both str... | codefeedback |
Write a Node.js program to find the sum of first n natural numbers using recursion. Additionally, optimize your solution by implementing memoization to store and reuse previously computed values. | codefeedback |
Rewrite the given HTML code into a valid HTML document by adding the necessary doctype declaration, head, and body tags, as well as adding some additional elements and CSS styling.
#Rewritten Test#
Create a responsive webpage with a header, a main content section, and a footer. The header should contain a logo and a n... | codefeedback |
Write a Bash script that prints the numbers 1 to 10 on one line, but in reverse order, without using any loops or conditionals. | codefeedback |
Write a SQL statement to list all the tables in a database that have at least 1000 rows, were created within the last month, and have a column named "status" which is not null and has a data type of integer. | codefeedback |
Create a for loop to print all the elements of the list in reverse order, but only for odd-indexed elements. Additionally, you must use a while loop to iterate through the list. The list should contain at least 10 elements, and each element must be unique and be of type string. Finally, you should implement a condition... | codefeedback |
Given a string, edit it so that every word starts with a capital letter and the rest of the word is in lowercase. Additionally, remove any leading or trailing spaces from the string.
Example:
Input: " this IS A TesT sTRinG "
Output: "This Is A Test String"
Note:
- You can assume that the input string will only contai... | codefeedback |
Given a string, remove all spaces from it, reverse the order of the characters, and convert all uppercase letters to lowercase.
string = 'This is a sample string' | codefeedback |
Create a dictionary of the declared states of India. The dictionary should be sorted in alphabetical order and each state name should be stored as a key. Additionally, each state should have a value associated with it, which should be a list of the top 5 major cities in that state. The cities in each state should be fu... | codefeedback |
Write a PHP script that prints the current hour, minute, second, and millisecond, while also calculating the sum of all the digits in the current time (hour + minute + second + millisecond).
Requirements:
- The script should use only a single loop for the calculations.
- The script should not use any built-in PHP func... | codefeedback |
Given a number n, write a function that finds the sum of the first n odd numbers, excluding any number divisible by both 3 and 5. | codefeedback |
Create a C# function to find the index of the first element of an array that is greater than a given value and divisible by 3. The array can contain both positive and negative numbers.
double[] arr = {-2.3, 1.1, -5.4, 2.00, 1.3, 9.7, 12.4};
double value = -4.0;
Requirements:
- The function should have a time complexi... | codefeedback |
Create a looping structure to display numbers from 1-1000, but you are not allowed to use any built-in looping statements or functions such as "for" or "while". The solution should have a time complexity of O(1) and a space complexity of O(1). | codefeedback |
Use Java's built-in sorting algorithm and write a code that sorts a list of objects of a custom class in ascending order based on a specific attribute. The custom class should have at least two attributes and a constructor to initialize them.
The custom class should also implement the Comparable interface and override... | codefeedback |
You are given two sets, A and B, with at most 10^4 elements each. Your task is to write a function, cartesian_product(A: set, B: set) -> set, that returns the Cartesian product of the two sets as a set.
The Cartesian product of two sets, A and B, is defined as the set of all possible ordered pairs (a, b) where a is an... | codefeedback |
Sort the given string in reverse alphabetical order and remove any duplicate characters. | codefeedback |
Create an HTML form to accept an email address and validate that the entered email address is in a valid format according to the standard email address specifications. Additionally, implement a server-side validation to check if the entered email address belongs to a valid domain. The form should display an error messa... | codefeedback |
Given an integer n, write a function to determine if it is a power of two.
Examples:
Input: n = 32
Output: True
Input: n = 12
Output: False | codefeedback |
Write a C program to sum the digits of a positive integer. The program should also print the average of the digits, the count of even digits in the integer, and the count of prime digits in the integer. | codefeedback |
Using Python, classify a given sentence into one of three categories: Animal, Plant, or Other. The classification must be based on a pre-trained machine learning model, and you must use the scikit-learn library for implementing the model. Additionally, the program should also provide the probability scores for each cat... | codefeedback |
Fix the following syntax error and sort the list in ascending order. The list should only contain positive integers. myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. However, you are not allowed to use any built-in sorting functions or libraries. | codefeedback |
Write an SQL query to group all customers with the same age and order the groups by the number of customers in each group in descending order. Additionally, only include groups that have more than 5 customers. | codefeedback |
Convert the following HTML to CSS, while also adding additional styling and requirements:
HTML:
```html
<body>
<h1>My Web Page</h1>
<p>This is a paragraph</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</body>
```
CSS:
- Set the background color of the `<body>` ... | codefeedback |
Write a SQL query to list all the customers whose age is between 18 and 25, and whose account balance is greater than $1000. The query should also exclude customers who have made more than 3 transactions in the last 30 days. | codefeedback |
Here is a list of strings and a specific string pattern. Write a code to return a list of all strings that match the pattern.
A pattern can consist of the following wildcard characters:
- "?" which matches any single character
- "*" which matches any sequence of characters (including an empty sequence)
The code shoul... | codefeedback |
Write a function to convert a list of characters into a string, but with the following additional constraints:
1. The function should handle cases where the input list is empty or contains only whitespace characters.
2. The function should remove any leading or trailing whitespace characters from the resulting string.
... | codefeedback |
Create a function to compute the area of a triangle when the length of its three sides are known. The sides of the triangle are represented by the variables a, b, and c.
The function should first check if the given sides can form a valid triangle. If the sides cannot form a valid triangle, the function should raise a ... | codefeedback |
Create a method to sort the data by the public_id in descending order. Additionally, the method should handle cases where multiple objects have the same public_id value. The sorting should be based on the name in ascending order for objects with the same public_id. However, the sorting should be done using a custom sor... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.