instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Develop an algorithm in Python to calculate the factorial of a given number n using recursion. The time complexity should be less than or equal to O(n) and the space complexity should be less than or equal to O(n). | codefeedback |
Write a JavaScript function that swaps the values of two variables, but without using a temporary variable. | codefeedback |
Create a coding program that sorts a given list of numbers into ascending order. The program should also remove any duplicate numbers from the list before sorting it. Additionally, the program should not use any built-in sorting functions or libraries to sort the list. [4, 3, 2, 5, 9, 1, 8] | codefeedback |
Write a JavaScript function that takes two arrays of integers and returns true if the arrays contain the same set of numbers, regardless of the order, and false otherwise.
#Example:
Input:
arr1 = [1, 2, 3, 4]
arr2 = [3, 4, 2, 1]
Output:
true
Input:
arr1 = [1, 2, 3, 4]
arr2 = [1, 2, 3]
Output:
false | codefeedback |
Generate PHP code to validate a username and password with the following requirements:
1. The username must be at least 6 characters long and no more than 20 characters long.
2. The username must only contain alphanumeric characters (a-z, A-Z, 0-9) and underscore (_).
3. The password must be at least 8 characters long... | codefeedback |
Develop a function to find all elements in a given array which appear more than once, but do not include the element 3 in the result.
nums = [4, 3, 6, 7, 3, 8, 4, 9] | codefeedback |
Develop a program that takes a positive integer greater than 1 and prints "true" if it is a prime number, and "false" otherwise. The program should also validate the input and handle invalid inputs by displaying an appropriate error message. | codefeedback |
Design a function to find the average of a given array, with the following additional requirements:
1. The function should be able to handle arrays containing both integers and floating-point numbers.
2. The function should return the average as a floating-point number with precision up to two decimal places.
3. The fu... | codefeedback |
Create a program to calculate the standard deviation of an array of numbers. The array can contain up to 10^6 elements.
# Additional Information:
- You are not allowed to use any built-in functions or libraries to calculate the standard deviation.
- The program should be able to handle both positive and negative numbe... | codefeedback |
Create an HTML table with three columns and ten rows. Each cell in the table should contain a randomly generated number between 1 and 100. Calculate the sum of all the numbers in the table and display it below the table. Additionally, highlight the cell with the highest number in each row with a different background co... | codefeedback |
Write a function to flatten a given array of lists, but only include the elements that are divisible by both 2 and 3.
[[1,2], [3,4], [5,6]] | codefeedback |
Develop an algorithm to print out the following pattern. The pattern should be printed in a zigzag manner, starting from the top left corner and ending at the bottom right corner. Each element in the pattern should be unique and the pattern should contain at least 10 rows and 10 columns. | codefeedback |
You need to code a program that converts a given number of seconds to years, months, weeks, days, hours, minutes, and seconds.
86400 seconds | codefeedback |
Implement a recursive binary search on a given sorted list of integers, and return the index of the target element if found. If the target element is not present in the list, return -1.
Example:
Input: [-4, -2, 0, 6, 7, 8], target = 0
Output: 2
Input: [1, 3, 5, 7, 9], target = 10
Output: -1
Note:
- You may assume t... | codefeedback |
Calculate the sum of all the prime numbers between a given range.
1000 and 2000 | codefeedback |
Create a function to sort a given set of strings in dictionary order, while ignoring leading whitespace and considering capitalization. Additionally, the function should handle cases where the strings contain special characters or numbers. | codefeedback |
Construct a python method to get the nth Fibonacci number, where n is a prime number greater than 2. | codefeedback |
Implement a method to check if a given string has all unique characters. The method should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Construct a python class to store a person's data like name, age, hobbies, and address. The address should consist of the street name, house number, city, state, and zip code. Implement a validation mechanism to ensure that the age is a positive integer and the zip code is a valid 5-digit number. Additionally, provide ... | codefeedback |
Create a Django view that displays all the books stored in the library's database, but also includes the following additional requirements:
1. Implement pagination to display only 10 books per page.
2. Add a search functionality to allow users to search for books by their titles.
3. Sort the books in ascending order b... | codefeedback |
Create a Pandas DataFrame from a given dictionary of lists, where the keys of the dictionary represent the column names and the values represent the column values. Ensure that the column names are in uppercase and the column values are in lowercase. The DataFrame should be sorted in descending order based on the values... | codefeedback |
Write a SQL statement to get all records from a table named "users" which has id between 5 and 10, and the "status" column is set to 'active'. | codefeedback |
Write a function in Java to calculate the sum of the even numbers in a given range of integers. The range of integers can be very large, up to 10^9. The function should have a time complexity of O(1) and a space complexity of O(1). | codefeedback |
Sort the given array of objects in ascending order by the 'name' field. However, if two objects have the same 'name', sort them based on the length of their 'lastname' in descending order. If two objects have the same 'name' and 'lastname' length, sort them based on the alphabetical order of their 'lastname'. Return th... | codefeedback |
Create a program in C to find the difference between the smallest and the largest number in a given array, but with the following constraints:
1. The program should not use any built-in sorting functions.
2. The program should find the difference in a single pass through the array, without iterating over the array mult... | codefeedback |
In C++, write a function to allocate memory for an array of integers. The function should also initialize each element of the array with the value 0. | codefeedback |
Write a SQL command to search for data containing a case-insensitive substring, but only for rows where the ItemDescription column starts with the letter 'C'. | codefeedback |
Write a function in Python to assign the value 0 for special values, i.e. empty strings and NaN. The function should handle nested lists and dictionaries as well.
#Example Input:
my_list = [5, 2, 3, None, '', 8]
my_dict = {'a': 1, 'b': '', 'c': None, 'd': [1, '', None]}
my_nested_list = [1, [2, '', [None]], {'a': '', ... | codefeedback |
Retrieve a random record from a MySQL table where the record must have a value greater than 100 in the 'age' column and the 'gender' column must be set to 'male'. Table Name: MemberTable | codefeedback |
Design a GUI in Python to accept user input and display a welcome message. Additionally, validate the user input to ensure it is a valid email address. If the input is not a valid email address, display an error message asking the user to enter a valid email address. | codefeedback |
Write a Java program to sort a list of strings alphabetically, but with the following additional requirement:
- The program should ignore any special characters or punctuation marks in the strings while sorting.
- The program should handle strings with different letter cases (uppercase and lowercase) and sort them acc... | codefeedback |
Explain the difference between a bubble sort and a merge sort algorithm. | codefeedback |
Modify the code snippet to filter all records from a table using SQL.
Table Name: StudentTable
Filter Type: Accepted
Filter Criteria: Include only students who have a GPA greater than 3.5 and are enrolled in the Computer Science program. | codefeedback |
Create a while loop in JavaScript to print out all the prime numbers between 20 and 30. | codefeedback |
Output the concatenation of two strings, but only include the letters that are vowels in both strings.
String1: "Hello"
String2: "world"
#Expected Output#
eoo | codefeedback |
Write a function in C# to calculate the area of a circle from its radius.
Additional Requirements:
- The function should handle negative radius values and return an error message if the radius is negative.
- The function should handle non-integer radius values and round the result to two decimal places.
- The function... | codefeedback |
Format the following date according to ISO 8601 standard.
date = 'January 5th, 2021'
Note: The date input may contain ordinal indicators (e.g. 1st, 2nd, 3rd, etc.) for the day. | codefeedback |
Modify the following function to print out the 'type' of each argument. The function should also check if the arguments are of specific types, where arg1 should be an integer and arg2 should be a string. If any of the arguments do not meet the specified type requirement, raise a TypeError with a custom error message. | codefeedback |
Generate code to parse the following HTML and extract the content of the first <p> tag as well as the text of each <li> tag within the <ul> tag, while ignoring any nested HTML tags. Additionally, the code should also handle the case where the <div> tag may contain multiple <p> tags and <ul> tags, and extract the conten... | codefeedback |
Define a function to collect unique values from a list of dictionaries based on the "key" field, where the key is a string and must be at least 3 characters long. The function should also return the unique values in descending order based on the "price" field, and if two values have the same price, they should be sorte... | codefeedback |
Write a Python program to multiply two matrices.
matrix1 = [[3, 5],
[6, 2]]
matrix2 = [[1, 2],
[3, 4]] | codefeedback |
Construct a REST API to get the list of current events from a Web Calendar application. Additionally, include functionality to add, update, and delete events from the calendar. | codefeedback |
Write a recursive Python function to calculate the factorial of a number, but with the additional requirement that the function must be tail recursive. | codefeedback |
Write a function in C++ to insert an item at the end of a singly linked list. | codefeedback |
In a Java program, write a method to find the longest common subsequence of two strings. The method should have a time complexity of O(n^2), where n is the length of the longest input string. Additionally, the solution should not use any built-in library functions or data structures. | codefeedback |
Create an Express application for a web store with endpoints for adding products, deleting products, viewing products, and updating product information. Implement authentication and authorization mechanisms to ensure only authenticated users can perform CRUD operations on products. Additionally, implement pagination fu... | codefeedback |
Write a JavaScript code snippet to check if a given string contains the substring 'hello' in a case-insensitive manner. The code should also count the number of times the substring appears in the string and return the indices of all occurrences of the substring. | codefeedback |
How can we generate a random number within a given range in Python and ensure that the generated number is unique within a list of numbers? | codefeedback |
Create a customer management system using Python and the Django web framework.
The system should allow users to perform the following tasks:
1. Register a new customer, including their name, email address, and phone number.
2. View a list of all registered customers.
3. Update the details of a customer, including the... | codefeedback |
Create a PostgreSQL database with two tables to store user details and user orders. The user details table should include fields for the user's name, email address, and phone number. The user orders table should include fields for the order ID, order date, total amount, and user ID (foreign key referencing the user det... | codefeedback |
Write a Haskell program to convert a given string to an Integer, where the string may contain negative numbers and decimal points.
string text = "-12.345" | codefeedback |
Suggest a way to sort a given array using insertion sort algorithm. The sorted array should be in descending order. The original array should remain unchanged.
int arr[] = {82, 2, 25, 14, 5, 9} | codefeedback |
Write a code snippet to delete all elements from a doubly linked list, ensuring that the deletion process takes constant time complexity. | codefeedback |
Construct a MySQL query to find the top 5 employees with the highest salaries and the highest number of years of experience. | codefeedback |
Write a function to compute a hash code for a string. The function should use a custom hashing algorithm that takes into account both the characters and the length of the string. | codefeedback |
Construct a HTML code which opens a popup window when a specific button is clicked. The popup window should display a random number between 1 and 100. The HTML code should also include a button that allows the user to close the popup window. | codefeedback |
Build a program in C to find all prime numbers within a given range, where the range is specified by the user as input. The program should prompt the user to enter the lower and upper bounds of the range. The program should then display the prime numbers within that range. | codefeedback |
Construct a function in Java to validate whether an input integer is a prime number. The function should handle negative input values and return a boolean value indicating whether the input integer is a prime number. The function should also check if the input integer is within the range of 1 to 1000. If the input inte... | codefeedback |
Write pseudocode to sort a given list of integers using bubble sort. The algorithm should be modified to sort the list in descending order. Additionally, you must ensure that the sorting process is optimized to have a time complexity of O(n^2). | codefeedback |
Generate a code in C to check if a sentence is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. The code should be able to handle sentences with spaces and punctuation.
char str[] = "A man, a plan, a canal, Panama!"
#Additional Requirement... | codefeedback |
Write a function in Python that takes a string as input and reorders the characters in it alphabetically. The function should return the reordered string.
Example:
Input: 'dcba'
Output: 'abcd'
Please note that the input string may contain both uppercase and lowercase letters, and the function should consider the case... | codefeedback |
What is the output of this Java program? Write a method called "printDetails" that takes in two parameters, a String variable called "name" and an int variable called "age". Inside the "printDetails" method, print the same output as in the given program. In the main method, call the "printDetails" method and pass in th... | codefeedback |
Write a regular expression to find all occurrences of a pattern in a string, where the pattern must be preceded by the word "quick" and followed by a whitespace character.
String: "The quick brown fox jumps over the quick lazy dog"
Pattern: "fox" | codefeedback |
Compare two given JSON objects and create a merged object. The merged object should have the following properties:
1. The "name" property should be the concatenation of the "name" properties of both objects.
2. The "age" property should be the average of the "age" properties of both objects, rounded down to the neares... | codefeedback |
Write an HTML page that displays a red box and a blue box next to each other. The red box should be on the left and the blue box should be on the right. | codefeedback |
What python library can be used for efficiently working with large-scale JSON data that contains nested structures and arrays? | codefeedback |
Suggest an algorithm to calculate the multiplication of two integers without using the operator '*'. In addition, the algorithm should have a time complexity of O(log n), where n is the value of the smaller integer. | codefeedback |
Compress a string using Huffman coding in Python.
String: "aaabbcc"
The time complexity of your solution should be O(n log n), where n is the length of the input string. | codefeedback |
Find the longest common subsequence for two strings in C++.
String 1: "abcdef"
String 2: "abdee"
Rewritten Test:
Write a C++ function that takes in two strings as input and returns the length of the longest common subsequence (LCS) between the two strings. The function should also print the actual LCS.
Example input:... | codefeedback |
Suggest an approach to add items to an array in JavaScript, while maintaining a constant time complexity. | codefeedback |
Develop a Python program to generate a list with numbers in range 3 to 12. The program should only include odd numbers in the list. | codefeedback |
Write a function in JavaScript that converts a JSON object to a string, while ensuring that all values of type 'string' are capitalized. The function should also remove any duplicate objects from the JSON before converting it to a string. | codefeedback |
Explain what the following function in Python does and analyze its time and space complexity.
def find_max_element_idx(arr):
"""
This function takes in an array 'arr' and returns the index of the maximum element in the array.
Args:
arr: A list of integers.
Returns:
max_idx: An integer represe... | codefeedback |
Compute the sum of all prime numbers between 1 and 50. | codefeedback |
Develop a C program to calculate the average of three numbers, but the numbers must be read from a file named "input.txt". The program should also write the result to a file named "output.txt" instead of displaying it to the user. | codefeedback |
Write a function to filter a given list such that all strings starting with an 'S' and ending with a vowel are removed from the list. Additionally, any strings containing numbers or special characters should also be removed.
['Swallow', 'Duck', 'Finch', 'Parrot', 'Sparrow', '3Duck', 'Eagle$'] | codefeedback |
Create a web scraper that can collect data from a web page. The web page is a dynamic site that requires JavaScript to load the content. The scraper should be able to wait for the content to load and then collect the data. The data should be stored in a database for further analysis. Additionally, the scraper should be... | codefeedback |
Code an algorithm to reverse an array of integers and return a new array without modifying the original array.
[1, 3, 4, 6, 8]
Provide a piece of erroneous code as a reference to increase misdirection:
#Erroneous Code#
```python
def reverse_array(nums):
reversed_nums = nums
reversed_nums.reverse()
return ... | codefeedback |
Write a function that takes as input a string and returns a new string with all the vowels removed. The function should have a time complexity of O(n), where n is the length of the input string, and should use constant space complexity. | codefeedback |
Increase the difficulty of the programming test question by requiring the table to be sorted based on the "age" field in ascending order. | codefeedback |
Write an algorithm that takes in an array and determines if it is a valid BST. The array can contain duplicates.
[9, 7, 3, 15, 20, 7] | codefeedback |
Write a code to generate a list of all possible permutations of a given string with the following additional constraints:
- The generated permutations should not contain any repeating characters.
- The generated permutations should be sorted in lexicographic order.
- The length of the given string will not exceed 10 ch... | codefeedback |
What are the steps involved in creating a new object in JavaScript? | codefeedback |
Replace the placeholder with a valid JavaScript expression using only bitwise operators, such that the value of x is the sum of the first 100 positive integers. | codefeedback |
Write a pseudo-code to implement a simple sorting algorithm that can handle duplicate elements efficiently. | codefeedback |
Can you write a code to delete all the items whose key starts with "item" from a given dictionary? The dictionary can contain any number of key-value pairs, and the keys can be of any length. The code should efficiently handle large dictionaries without causing memory or performance issues. | codefeedback |
Classify this text as either positive or negative. Consider the following factors:
1. Identify negation words: Analyze the text for negation words such as "not," "never," or "don't." These words indicate a negative sentiment.
2. Evaluate intensity: Look for words that express strong emotions or extreme opinions. Thes... | codefeedback |
Write a code to output whether a given number is even or odd. The code should also handle negative numbers and decimal numbers. The program should display an error message if the input is not a valid number. | codefeedback |
Write a method that takes 2 strings and determines if the first string contains the second string as a substring. The method should ignore case sensitivity and whitespace characters.
Example:
String 1: "The quick brown fox jumps over the lazy dog"
String 2: "The Lazy Dog"
The method should return True because the fi... | codefeedback |
Write a PHP script to convert a decimal number to binary format. | codefeedback |
Given a number N, write a function to check if N is prime.
To solve this problem, we can follow the steps below:
1. Start by checking if N is less than 2. If it is, return False since prime numbers are greater than 1.
2. Iterate from 2 to the square root of N (inclusive) and check if any of these numbers divide N ev... | codefeedback |
Design a class with 3 data members in Python, where one of the data members must be a nested dictionary. | codefeedback |
Write a function that takes in a list of elevations representing the heights of mountains in meters. Find the highest peak in the list and return its index. If there are multiple peaks with the same height, return the index of the first occurrence.
The function should have a time complexity of O(n) and a space comple... | codefeedback |
Develop a web application that allows users to create an account. The application should have the following requirements:
1. Users should be able to register by providing their name, email, and a valid phone number.
2. The application should validate the user's input for each field:
- Name should be at least 3 char... | codefeedback |
What is the maximum number of threads simultaneously running in a single process on a system with a 32-bit architecture? | codefeedback |
Implement the Floyd's Cycle algorithm to detect a cycle in a linked list. Additionally, modify the algorithm to return the starting node of the cycle if one exists. | codefeedback |
Create a JavaScript function to remove all spaces and special characters from a string, and return the resulting string in reverse order. The function should have a time complexity of O(n) and should not use any built-in JavaScript functions such as `replace` or `reverse`. | codefeedback |
Reverse a string without using the reverse() function or any built-in string manipulation functions.
#Additional Instructions#
1. You are not allowed to use any built-in string manipulation functions such as `slice()`, `substring()`, `splice()`, `join()`, etc. You can only use basic operations like accessing individu... | codefeedback |
In Java, write a function for calculating the Fibonacci number for a given input n.
However, you are not allowed to use recursion to solve this problem. You must use an iterative approach instead. | codefeedback |
Sort a list of integers in ascending order using selection sort.
[ 9, 5, 2, 0, 7, 4, 1, 8, 6, 3]
In addition to sorting the list, also remove any duplicate values that appear in the list. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.